-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
51 lines (43 loc) · 1.48 KB
/
main.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include "random.h"
#define LINEBREAK std::cout << "--------\n";
int main()
{
unsigned char rByte = Random::getRandomByte();
std::cout << "Get a single random byte using static method: " << (int)rByte << '\n';
LINEBREAK;
// Initialise with a size_t n, generates vector with n random bytes.
// ----------------------------------------------------------------
Random r{10};
std::cout << "Initialise with a size:\n";
r.printInt();
r.setRandomBytes(); // Reset random buffer with fresh bytes
std::cout << "Reset the random buffer with fresh bytes: setRandomBytes()\n";
r.printHex();
r.printInt();
std::cout << "Custom output:\n";
for (auto& el: r.getRandomBytes()) {
std::cout << std::setw(2) << std::setfill('0') << std::hex << (int)el;
}
std::cout << '\n';
LINEBREAK;
// If initialised with a suitable vector, fill vector with random values.
// ----------------------------------------------------------------------
std::vector<unsigned char> buf(5);
Random r2(buf);
std::cout << "Insert random bytes into buffer:\n";
for (auto& el : buf)
std::cout << (int)el << " ";
std::cout << '\n';
std::cout << "Print using static methods:\n";
Random::printInt(buf);
Random::printHex(buf);
LINEBREAK;
// Populate a buffer with random bytes statically.
// ----------------------------------------------
std::cout << "Populate a buffer with random bytes statically.\n";
std::vector<unsigned char> s(10);
Random::setBuffer(s);
Random::printHex(s);
return 0;
}