-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_random.cpp
40 lines (36 loc) · 981 Bytes
/
make_random.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
//
#include <iomanip>
#include <iostream>
#include <random>
#include <string>
int
main(int argc, char** argv)
{
auto vname{argc > 1 ? argv[1] : "Random"};
auto n = argc > 2 ? std::atoi(argv[2]) : 32;
auto s = argc > 3 ? std::atoi(argv[3]) : 32;
std::random_device rnd;
std::mt19937 mtrand{rnd()};
std::mt19937_64 mtrand64{rnd()};
auto mask = s == 64 ? ~0 : (1ULL << s) - 1;
auto column = (s + 3) / 4;
std::cout << std::hex << std::setfill('0');
std::cout << "// mask = " << mask << std::endl;
if (s > 32)
std::cout << "unsigned long long ";
else
std::cout << "unsigned int ";
std::cout << vname << "[] = {";
for (int i = 0; i < n; i++)
{
int cnt = i % 4;
std::cout << (cnt == 0 ? "\n 0x" : " 0x");
if (s > 32)
std::cout << std::setw(column) << (mtrand64() & mask);
else
std::cout << std::setw(column) << (mtrand() & mask);
std::cout << ",";
}
std::cout << "\n};" << std::endl;
return 0;
}