Skip to content

Instantly share code, notes, and snippets.

@summerlight
Created October 1, 2013 15:58
Show Gist options
  • Select an option

  • Save summerlight/6780771 to your computer and use it in GitHub Desktop.

Select an option

Save summerlight/6780771 to your computer and use it in GitHub Desktop.
random number generation with discrete probability in C++11
#include <random>
#include <map>
#include <iostream>
int main()
{
using namespace std;
mt19937 engine;
discrete_distribution<> dist = {10, 20, 30, 40};
map<int, int> result;
for (auto i = 0; i < 100000; i++) {
result[dist(engine)]++;
}
for (auto&& count : result) {
cout << count.second << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment