QuasarAppLib
qaglobalutils.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2018-2025 QuasarApp.
3
* Distributed under the lgplv3 software license, see the accompanying
4
* Everyone is permitted to copy and distribute verbatim copies
5
* of this license document, but changing it is not allowed.
6
*/
7
8
#include "
qaglobalutils.h
"
9
#include <limits>
10
11
template
<
class
NUM>
12
void
gen
(
int
size, QByteArray &result) {
13
for
(; size > 0; size -=
sizeof
(NUM)) {
14
NUM random = (rand() * rand()) % std::numeric_limits<NUM>::max();
15
result.insert(0,
reinterpret_cast<
char
*
>
(&random),
sizeof
(random));
16
}
17
}
18
// to do. The random function should generate 4 bit numbers anywhere except last number
19
void
randomArray
(
int
size, QByteArray &result) {
20
if
(size %
sizeof
(
unsigned
long
long
) == 0) {
21
gen<unsigned long long>
(
size
,
result
);
22
}
else
if
(
size
%
sizeof
(
unsigned
int
) == 0) {
23
gen<unsigned int>
(
size
,
result
);
24
}
else
if
(
size
%
sizeof
(
unsigned
short
) == 0) {
25
gen<unsigned short>
(
size
,
result
);
26
}
else
{
27
gen<unsigned char>
(
size
,
result
);
28
}
29
}
gen
void gen(int size, QByteArray &result)
Definition
qaglobalutils.cpp:12
randomArray
void randomArray(int size, QByteArray &result)
randomArray This function return random arrat with size size
Definition
qaglobalutils.cpp:19
qaglobalutils.h
qaglobalutils.cpp
Generated by
1.9.8