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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -