1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "common_tool.h" 17 18 using namespace std; 19 using namespace OHOS::MediaAVCodec; 20 CommonTool()21CommonTool::CommonTool() 22 { 23 srand(time(nullptr) * 10); // 10 24 } 25 GetRandString()26string CommonTool::GetRandString() 27 { 28 string str; 29 int32_t len = rand() % STRING_LEN; 30 char c; 31 for (int32_t idx = 0; idx < len; idx++) { 32 c = rand() % CONSTASNTS; 33 str.push_back(c); 34 } 35 return str; 36 } 37 GetRandInt()38int32_t CommonTool::GetRandInt() 39 { 40 return RAND_INT_MIN + rand() % (RAND_INT_MAX - RAND_INT_MIN + 1); 41 } 42 GetRandLong()43int64_t CommonTool::GetRandLong() 44 { 45 return RAND_INT_MIN + rand() % (RAND_INT_MAX - RAND_INT_MIN + 1); 46 } 47 GetRandFloat()48float CommonTool::GetRandFloat() 49 { 50 return (float)rand() / RAND_MAX * (DOUBLE_MAX - DOUBLE_MIN) + DOUBLE_MIN; 51 } 52 GetRandDouble()53double CommonTool::GetRandDouble() 54 { 55 return (double)rand() / RAND_MAX * (DOUBLE_MAX - DOUBLE_MIN) + DOUBLE_MIN; 56 }