diff --git a/qaglobalutils.cpp b/qaglobalutils.cpp new file mode 100644 index 0000000..d8f3c8d --- /dev/null +++ b/qaglobalutils.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2018-2021 QuasarApp. + * Distributed under the lgplv3 software license, see the accompanying + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. +*/ + +#include "qaglobalutils.h" + +template +void gen(int size, QByteArray &result) { + for (; size >= 0; size -= sizeof(NUM)) { + NUM random = (rand() * rand()) % std::numeric_limits::max(); + result.insert(0, reinterpret_cast(&random), sizeof(random)); + } +} + +void randomArray(int size, QByteArray &result) { + if (size % sizeof(unsigned long long) == 0) { + gen(size, result); + } else if (size % sizeof(unsigned int) == 0) { + gen(size, result); + } else if (size % sizeof(unsigned short) == 0) { + gen(size, result); + } else { + gen(size, result); + } +} diff --git a/qaglobalutils.h b/qaglobalutils.h index 07955e5..bde9eb1 100644 --- a/qaglobalutils.h +++ b/qaglobalutils.h @@ -12,6 +12,7 @@ #include #include #include +#include #include "QtGlobal" @@ -182,4 +183,11 @@ uint8_t static_type_hash_8(T& object) noexcept { #define debug_assert(condition, msg) assert(condition && msg) #endif +/** + * @brief randomArray This function return random arrat with size @a size + * @param size This is size of needed array. + * @param result This is result value of generated array. +*/ +void randomArray(int size, QByteArray &result); + #endif // GLOBAL_H