random value from a probability distribution

Quote:

> I would like to choose a value for X by drawing a random number from a

> probability distribution.. in fortran77..

> I have 201 values possible for a variable X. for each of this value I

> have calculated a probability distribution and I would like to picks a

> value for X from this probability distribution..

> Thank you.

I think maybe you mean that X can take discrete values, and you have

determined the probability p(i) that X takes the value x(i), such that

Sum(p(i),i=1,201) = 1.0.

If this is your situation then the answer is very simple.

First generate a value R from a uniform distribution, using the random

number generator that your Fortran compiler supplies (you can do better

than this, but I doubt that you care). This is a value between 0 and 1.

You then want to find the number k such that:

Sum(p(i),i=1,k-1) < R

and

Sum(p(i),i=1,k) >= R

The value of X corresponding to R is then x(k).

Gib

------------ And now a word from our sponsor ---------------------

For a secure high performance FTP using SSL/TLS encryption

upgrade to SurgeFTP

---- See http://netwinsite.com/sponsor/sponsor_surgeftp.htm ----