-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexec24-10.cpp
More file actions
30 lines (25 loc) · 763 Bytes
/
exec24-10.cpp
File metadata and controls
30 lines (25 loc) · 763 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
#include <iostream>
#include <random>
#include <string>
#include <vector>
using namespace std;
int randint(int min, int max) {
static random_device rd;
static default_random_engine gen(rd());
return uniform_int_distribution<>(min, max)(gen);
}
// Take two integers n and d as inputs, call randint(n) d times,
// and output the number of draws for each of [0:n).
int main(int argc, char* argv[]) {
if (argc < 3) {
cout << "Usage: " << argv[0] << " n d\n";
return 0;
}
int n = stoi(argv[1]), d = stoi(argv[2]);
vector<int> hist(n);
for (int i = 0; i < d; ++i)
++hist[randint(0, n - 1)];
for (int i = 0; i < hist.size(); ++i)
cout << i << '\t' << string(hist[i], '*') << '\n';
return 0;
}