2022-02-10 20:02:48 +03:00
|
|
|
/*
|
2024-12-30 22:39:49 +01:00
|
|
|
* Copyright (C) 2018-2025 QuasarApp.
|
2022-02-10 20:02:48 +03:00
|
|
|
* 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"
|
2022-02-11 17:21:01 +03:00
|
|
|
#include <limits>
|
2022-02-10 20:02:48 +03:00
|
|
|
|
|
|
|
template<class NUM>
|
|
|
|
void gen(int size, QByteArray &result) {
|
2023-02-24 20:53:06 +01:00
|
|
|
for (; size > 0; size -= sizeof(NUM)) {
|
2022-02-10 20:02:48 +03:00
|
|
|
NUM random = (rand() * rand()) % std::numeric_limits<NUM>::max();
|
|
|
|
result.insert(0, reinterpret_cast<char*>(&random), sizeof(random));
|
|
|
|
}
|
|
|
|
}
|
2022-07-26 13:09:04 +03:00
|
|
|
// to do. The random function should generate 4 bit numbers anywhere except last number
|
2022-02-10 20:02:48 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|