The function rand() supplies a number between 0 and RAND_MAX (where RAND_MAX is supplied in <stdlib.h>, and is different for different compiler implementations). The function rand() is supposed to supply uniformly distributed values. You can do various statistical tests to see if it is adequate for your purposes.
So the following supplies a number between 0 and 1. I have left out most of the code, but here's what you need:
Code:
#include <stdlib.h>
...
double rand_value;
...
rand_value = (double)rand()/RAND_MAX;
...
Now, if you want p(heads) = 1/3, you get random numbers from the above code snippet, and if the value is less than 1/3, you assign 'H', otherwise assign 'T' to the current coin toss.
Does this help?
Dave