how to bias a random number generator

2020-02-15 02:47发布

问题:

i am using the random number generator provided with stl c++. how do we bias it so that it produces smaller random numbers with a greater probability than larger random numbers.

回答1:

Well, in this case you probably would like a certain probability distribution. You can generate any distribution from a uniform random number generator, the question is only how it should look like. Rejection sampling is a common way of generating distributions that are hard to describe otherwise, but in your case something simpler might suffice.

You can take a look at this article for many common distribution functions. Chi, Chi-Square and Exponential look like good candidates.



回答2:

One simple way would be to take every random number generated in the range [0,1) and raise it to any power greater than 1, depending how skewed you want the results



回答3:

Use std::discrete_distribution to calculate random numbers with a skewed probability distribution. See example here: http://www.cplusplus.com/reference/random/discrete_distribution/



标签: c++ random