-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinear_congruential.cpp
More file actions
37 lines (30 loc) · 1013 Bytes
/
Copy pathlinear_congruential.cpp
File metadata and controls
37 lines (30 loc) · 1013 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
#include <chrono>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
std::vector<long double> getDecimalFractions(unsigned long n_samples) {
auto seed =
std::chrono::high_resolution_clock::now().time_since_epoch().count();
std::minstd_rand gen(seed);
std::uniform_real_distribution<> dis(0.0, 1.0);
std::vector<long double> result(n_samples);
for (unsigned long i = 0; i < n_samples; i++) {
result[i] = dis(gen);
}
return result;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
std::cout << "Usage: ./linear_congruential {n_samples}" << std::endl;
return 1;
}
unsigned long n_samples = std::strtoul(argv[1], nullptr, 10);
std::vector<long double> result = getDecimalFractions(n_samples);
std::cout << std::fixed << std::setprecision(20);
std::cout << "Linear Congruential Numbers" << std::endl;
for (const auto &num : result) {
std::cout << num << std::endl;
}
return 0;
}