1 /* 2 * Copyright (C) 2021 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 #ifndef UTILS_H 17 #define UTILS_H 18 19 #include <cstdio> 20 #include <cstring> 21 #include <ctime> 22 #include <string> 23 24 #include "securec.h" 25 #include "utils/log/aie_log.h" 26 27 /** 28 * return random number n: 0 <= n <= max 29 */ 30 int GetRandomInt(int max); 31 32 /** 33 * Return true of false by random. 34 */ 35 bool GetRandomBool(); 36 37 /** 38 * Gets current system date and time in format of YYYYMMDDhhmmss. E.g. 20201109123000. 39 */ 40 std::string GetSystemTime(); 41 42 /** 43 * Generates a string with specified length by random. 44 * 45 * len Length of string + 1, e.g. to generate a 20-bit string, set the input parameter len to 21. 46 * str The string to be generated. 47 */ 48 void GetRandomString(const int len, char *str); 49 50 /** 51 * Save characters to txt Document. 52 * 53 * input a string to be saved in the file. 54 * path path and filename of result text 55 */ 56 void SaveCharTextAppend(char *input, char *path); 57 58 /** 59 * Save strings to txt Document. 60 * 61 * input a string to be saved in the file. 62 * path path and filename of result text 63 */ 64 void SaveStringTextAppend(std::string input, std::string path); 65 66 #endif