-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.cpp
More file actions
38 lines (31 loc) · 899 Bytes
/
random.cpp
File metadata and controls
38 lines (31 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "random.h"
int RandomInt(int lowerBound, int upperBound) {
if (!seeded) {
std::srand(static_cast<unsigned int>(std::time(nullptr)));
seeded = true;
}
return lowerBound + std::rand() % (upperBound - lowerBound + 1);
}
std::string GenerateRandomBytes(int len) {
if (!seeded) {
std::srand(static_cast<unsigned int>(std::time(nullptr)));
seeded = true;
}
std::string randomBytes(len, 0);
for (auto& byte : randomBytes) {
byte = static_cast<char>(std::rand() % 256);
}
return randomBytes;
}
std::string GenerateRandomBytes(int lowerBound, int upperBound) {
if (!seeded) {
std::srand(static_cast<unsigned int>(std::time(nullptr)));
seeded = true;
}
int length = lowerBound + std::rand() % (upperBound - lowerBound + 1);
std::string randomBytes(length, 0);
for (auto& byte : randomBytes) {
byte = static_cast<char>(std::rand() % 256);
}
return randomBytes;
}