If you are still having trouble with getting the random number generator
to work. Try something like the following to pick the height for a new node.
(Note that this procedure counts the number of flips to the first head.)
int flips=1;
if (Math.random()<.5){
flips++;
}
Courtesy of Aaron Averbuch.
AltFairCoin.java --- alternate class for a fair coin. Although
the provided nextInt() method should be positive with probability 1/2,
it is not. This procedure is an attempt to correct problems with
Java's random number generator. It should do a btter job of
generating a coin flip that returns a boolean that is true with
probability 1/2 and false with probality 1/2.
FairCoin.java --- class for a fair coin. It has a method to generate
a coin flip that returns a boolean that is true with probability 1/2 and
false with probality 1/2.
Example.java A sample procedure to simulate
the process of counting how many coin flips it takes to flip a head.
hash-test The test data.