-
Notifications
You must be signed in to change notification settings - Fork 26
/
gen_lognormal.cpp
46 lines (38 loc) · 1012 Bytes
/
gen_lognormal.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
//
// Generates 190M values drawn from a
//
#include <iostream>
#include <random>
#include <algorithm>
#include <fstream>
#include <climits>
#include <set>
#include <vector>
int main()
{
double scale = 1e+9;
double max = double(INT_MAX) / scale;
int nelements = 190000000;
std::mt19937 rng;
rng.seed(std::random_device()());
std::lognormal_distribution<double> dist(0.0, 2.0);
std::set<int> samples;
while (samples.size() < nelements) {
double r = dist(rng);
if (r > max) continue;
samples.insert(int(r * scale));
if (samples.size() % 1000000 == 0) {
std::cerr << "Generated " << samples.size() << std::endl;
}
}
std::vector<int> vec(samples.begin(), samples.end());
std::sort(vec.begin(), vec.end());
std::cerr << "min = " << vec[0] << std::endl;
std::cerr << "max = " << vec[vec.size() - 1] << std::endl;
FILE *fout = fopen("lognormal.sorted.190M", "wb");
for (int x : vec) {
fwrite(&x, sizeof(x), 1, fout);
}
fclose(fout);
return 0;
}