-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.cpp
More file actions
executable file
·34 lines (26 loc) · 892 Bytes
/
generate.cpp
File metadata and controls
executable file
·34 lines (26 loc) · 892 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
#include <fstream>
#include <iostream>
#include <random>
static const char filename[] = "unsorted.bin";
int main(int argc, char* argv[])
{
if (argc < 2) {
std::cout << "Generates 'unsorted.bin' file with N random integers." << std::endl;
std::cout << "N can be in scientific notation. e.g., 1E6." << std::endl;
std::cout << "Usage: " << std::endl;
std::cout << argv[0] << " N" << std::endl;
exit(0);
}
unsigned nvalues = std::stod(argv[1]);
std::ofstream fs;
fs.open(filename, std::ios::out | std::ios::binary);
std::random_device rd;
std::default_random_engine re(rd());
std::uniform_int_distribution<unsigned int> dist;
for (unsigned int i = 0; i < nvalues; ++i) {
unsigned int number = dist(re);
fs.write(reinterpret_cast<char*>(&number), sizeof(number));
}
fs.close();
return 0;
}