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 
21 constexpr uint32_t NUM_10 = 10;
22 
CommonTool()23 CommonTool::CommonTool()
24 {
25     srand(time(nullptr) * NUM_10);
26 }
27 
GetRandString()28 string CommonTool::GetRandString()
29 {
30     string str;
31     int32_t len = rand() % STRING_LEN;
32     char c;
33     for (int32_t idx = 0; idx < len; idx++) {
34         c = rand() % CONSTASNTS;
35         str.push_back(c);
36     }
37     return str;
38 }
39 
GetRandInt()40 int32_t CommonTool::GetRandInt()
41 {
42     return RAND_INT_MIN + rand() % (RAND_INT_MAX - RAND_INT_MIN + 1);
43 }
44 
GetRandLong()45 int64_t CommonTool::GetRandLong()
46 {
47     return RAND_INT_MIN + rand() % (RAND_INT_MAX - RAND_INT_MIN + 1);
48 }
49 
GetRandFloat()50 float CommonTool::GetRandFloat()
51 {
52     return (float)rand() / RAND_MAX * (DOUBLE_MAX - DOUBLE_MIN) + DOUBLE_MIN;
53 }
54 
GetRandDouble()55 double CommonTool::GetRandDouble()
56 {
57     return (double)rand() / RAND_MAX * (DOUBLE_MAX - DOUBLE_MIN) + DOUBLE_MIN;
58 }