how to bias a random number generator

2020-02-15 02:26发布

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.

标签: c++ random
3条回答
Evening l夕情丶
2楼-- · 2020-02-15 03:01

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楼-- · 2020-02-15 03:11

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

查看更多
【Aperson】
4楼-- · 2020-02-15 03:21

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.

查看更多
登录 后发表回答