In C++, How Can I Generate A Random Number Based Off Of A Double Value Probability? -


i have event should have 0.5% probability of occurring (not often).

how can generate random number based on probability?

would sufficient, don't believe srand returns integer...

double rate = 0.05; if((srand() % 100) < rate) {     std::cout << "event occurred" << endl; } 

std::mt19937 rng(std::random_device{}()); std::bernoulli_distribution d(0.005); bool b = d(rng); // true 0.5% of time; otherwise false 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -