-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathsample.cpp
More file actions
35 lines (31 loc) · 820 Bytes
/
sample.cpp
File metadata and controls
35 lines (31 loc) · 820 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
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
using namespace std;
const string population = "ABCD";
const size_t n_samples{ 1'000'000 };
mt19937_64 urbg;
void sample_length(size_t n) {
cout << "-- Length " << n << " --\n";
map<string, size_t> counts;
for(size_t i{}; i < n_samples; i++) {
string result;
sample(population.begin(), population.end(), back_inserter(result), n, urbg);
counts[result]++;
}
for(const auto& [sample, count] : counts) {
const auto percentage = 100 * count / static_cast<double>(n_samples);
cout << percentage << " '" << sample << "'\n";
}
}
int main() {
cout << fixed << setprecision(1);
sample_length(0);
sample_length(1);
sample_length(2);
sample_length(3);
sample_length(4);
}