QuasarAppLib/qaglobalutils.cpp
EndrII 4c596e3088
All checks were successful
buildbot/IOSCMakeBuilder Build finished.
update copyright
2022-03-03 19:00:49 +03:00

30 lines
949 B
C++

/*
* Copyright (C) 2018-2022 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"
#include <limits>
template<class NUM>
void gen(int size, QByteArray &result) {
for (; size >= 0; size -= sizeof(NUM)) {
NUM random = (rand() * rand()) % std::numeric_limits<NUM>::max();
result.insert(0, reinterpret_cast<char*>(&random), sizeof(random));
}
}
void randomArray(int size, QByteArray &result) {
if (size % sizeof(unsigned long long) == 0) {
gen<unsigned long long>(size, result);
} else if (size % sizeof(unsigned int) == 0) {
gen<unsigned int>(size, result);
} else if (size % sizeof(unsigned short) == 0) {
gen<unsigned short>(size, result);
} else {
gen<unsigned char>(size, result);
}
}