Archived

This topic is now archived and is closed to further replies.

Ys

Biased Random number

Recommended Posts

i wish to create a biased random number routine but i have found very little information on it, i need it too generate a random number either 0 or 1 but i need it biased towards 1 please help i havent really got a clue and i am just messing about with ideas. Thanks for any help Chris

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just a thought get a random number 0,1,2 .. and if it is anything other than 0, have it equal 1. That way you have more chances of having a "1" than 0.

Share this post


Link to post
Share on other sites
The solution is actually quite easy since you require only a binary output (0 or 1).

Step 1: Generate a random number between 0 and 1 using a function like rand().

(I don''t actually advocate using the C standard library function rand() however it''s probably what you have on hand, so start there.)

Step 2: If this random number is greater than your bias (which is also a number between 0 and 1, then return 1, otherwise return 0.

How this works... choose a bias, p (between 0 and 1), that indicates what proportion of samples should be 0. Clearly 1-p represents the proportion of samples that should be 1. Sampling n random numbers on [0,1] will return n*p numbers <=p and n*(1-p) numbers >p (if n is large enough)!

I hope this helps!

Cheers,

Timkin

Share this post


Link to post
Share on other sites
Most standard random number generators produce a uniform distribution of random numbers, not biased towards anything---just giving a number between 0 and 1.

You can always take the output of the standard generator and map it to another distribution that does bias the result. For example, you''re probably aware of the "normal" or "bell-curve" distribution shape. This distribution biases the points towards the median, with most of the values appearing between perhaps 0.25 and 0.75.

The mapping between a uniform random number and a particular distribution is done using a "Quantile" function. The distribution function will look something like:

R = F(U)

Here, R is the biased random number, the thing you want to calculate. U is the random number that is generated by a uniform random number functon such as rand(). And F(U) is the Quantile function. This function may be written as an inverse of the cumulative distribution function (CDF).

All you have to do to get your biased number is call rand() to get the uniform random number---and scale it to be between 0 and 1. Then calculate the Quantile function F(U) to get the biased random number.

If you want to bias the output towards 1, consider using the Beta distribution, which provides a bias towards 0. You can flip the bias by first evaluating the number and then reversing it: R = 1 - R.

The following web site has details on the Beta distribution, including Quantile function formulas that you can use.

http://www.math.uah.edu/stat/special/index.html

I''ve done some work for you here. For the Beta distribution, use this Quantile function:

F(U) = U(1/a)

Then, to bias towards 1 and not 0,

F(U) = 1 - U(1/a)

Here, a is a shape parameter. Try a = 0.1. If you want more points near 1, then decrease the value of a. If you want fewer points near 1, then increase the value of a.

Be sure and try out the "Quantile Applet" java app on the web site. It shows you the shape of the different distributions. It plots the CDF curve, which is just a 90-degree rotated Quantile function curve.

There are other distributions you can use as well. The Weibull and Pareto distributions also provide a bias towards 0, but they are tricky since the Quantile functions generate values of F(U) that are much much greater than 1.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites