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