Semi-random numbers generation in C++ -


this question has answer here:

suppose have set of numbers x = {0, 0, 0, 0, 1, 2, 2, 3}. there way me use rand() print out random numbers list proportion of generated numbers on time original proportion of numbers in set? in other words, proportion of zeros 0.5, ones 0.125, twos 0.25, , threes 0.125.

you can specifying frequencies:

#include <iostream> #include <random>  int main() {     using namespace std;     mt19937_64 engine;      discrete_distribution<int> numbers{4, 1, 2, 1};      cout << numbers(engine) << endl; } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -