How to offset random number generator

I am using a random number generator provided with stl C ++. how do we shift it so that it produces smaller random numbers more likely than larger random numbers.

+2
source share
3 answers

Well, in this case, you probably need a certain probability distribution. You can generate any distribution from a uniform random number generator, the only question is how it should look. Filtering a sample is a common way to generate distributions that are hard to describe otherwise, but in your case something might be simpler.

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

+6
source

One simple way is to take each random number generated in the range [0,1) and raise it to any power greater than 1, depending on how distorted you want the results

+6
source

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

0
source

Source: https://habr.com/ru/post/914218/


All Articles