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 -

java - Could not locate OpenAL library -

Non Unique Username with ASP.Net Identity 2.0 -