views:

216

answers:

2

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.

+5  A: 

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.

Joey
+4  A: 

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

Gareth
Only problem is that this will skew the results toward the bigger numbers. Perhaps `1-x^n` or `x^n` with n below 1.
Tordek
No, it won't; 0.5 ^ 1.4 ~== 0.38. So long as 0<x<1 and n>1, x^n < x
Gareth