language: C++11 (gcc-4.7.2)
date: 347 days 13 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <vector>
#include <map>
#include <random>
 
int main()
{
// no hardware access on ideone
//    std::random_device rd;
//    std::mt19937 gen(rd());
    std::mt19937 gen(time(NULL));
 
    std::vector<double> p = {0, 1.0/15, 2.0/15, 3.0/15, 4.0/15, 5.0/15};
    std::discrete_distribution<> d(p.begin(), p.end());
    std::map<int, int> m;
    for(int n=0; n<10000; ++n) {
        ++m[d(gen)];
    }
    for(auto i = m.begin(); i!=m.end(); ++i) {
        std::cout << i->first << " generated " << i->second << " times\n";
    }
}