View Single Post
  #7 (permalink)  
Old August 25th, 2004, 08:45 AM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

From the original post:

Quote:
quote:

i want to tell it p(heads)=1/3
p(tails)=2/3
That is, the coin is not balanced (since for a "fair" coin and a "fair" toss, we would expect p(heads) to be 1/2.)


The function rand() is designed to give numbers with a uniform distribution between 0 and RAND_MAX.

If this is true, then the numbers obtained from the expression

x = rand()/RAND_MAX

are uniformly distributed between 0 and 1.

So for any integer N>0, let p = 1/N, then the probability that x is less than p is p. (So for, example, the probability that x is less than 1/3 is 1/3 and the probability that x is greater than or equal to 1/3 is 2/3). Therefore, if we assign the value 'H' whenever the number is < 1/3, and 'T' otherwise, we have simulated the coin toss as the Original Post requested.

Of course, if we run this experiment for, say 12 tosses, we may not get exactly 4 'H' and 8 'T', but for large numbers of tosses, we expect to have 'H' about 1/3 of the time. That's what is meant by the expression "probability of 'H' is 1/3".


Dave
Reply With Quote