View Single Post
  #4 (permalink)  
Old August 24th, 2004, 01:21 PM
davekw7x davekw7x is offline
Authorized User
 
Join Date: Feb 2004
Posts: 76
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, if rand() gives uniformly distributed values, then the formula that I used will give values that are <1/3 one third of the time. Assigning 'H' to values < 1/3 is a way of simulating a coin toss with p(heads) = 1/3.

Code:
char toss_value;

if (rand()/RAND_MAX) < 1.0/3.0 {
  toss_value = 'H';
}
else {
  toss_value = 'T';
}
Why would you have a problem with this?

Dave
Reply With Quote