Utility
Class Geometric

java.lang.Object
  |
  +--Utility.RandomNumber
        |
        +--Utility.Geometric

public class Geometric
extends RandomNumber

Geometric is used to generate random variables from the geometric distribution. The random variable represents the position of the the first success in an infinite sequence of Bernoulli trials. The probability of success of each trial is identical and is given by fProbSuccess. This value is passed to the constructor to initialize the object.
This algorithm is kind of slow if p is very small since we have to keep running trials until we observe a success. If p = 0.0001, this could take quite a while ...
See Knuth Vol 2 for a faster algorithm using logarithms.

This is a discrete distribution.

Tests Performed
1000 samples were generated and the means and variances were examined. Subjectively, they seemed correct. A goodness of fit test was performed with 100 samples and 10 intervals. It succeeded about 19/20 times.


Constructor Summary
Geometric(double probSuccess)
           
 
Method Summary
 double sampleDouble()
          Draw a random sample.
 int sampleInt()
          Generate a geometrically distributed random variable.
 
Methods inherited from class Utility.RandomNumber
goodnessOfFitTest, goodnessOfFitTest, randomMixer, resetRandomMixer, sample01
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Geometric

public Geometric(double probSuccess)
Method Detail

sampleInt

public int sampleInt()
Generate a geometrically distributed random variable.

Overrides:
sampleInt in class RandomNumber
Returns:
The index of the first observed success in an infinite sequence of bernoulli trials.
See Also:
Geometric(double)

sampleDouble

public double sampleDouble()
Description copied from class: RandomNumber
Draw a random sample. This function should be overridden by all derived classes. The RandomNumber class returns a uniform double in the interval [0,1).

Overrides:
sampleDouble in class RandomNumber