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
Post a Comment