edu.indiana.util.distribution
Class UniformDistribution

java.lang.Object
  extended by edu.indiana.util.distribution.UniformDistribution
All Implemented Interfaces:
Distribution, java.io.Serializable, java.lang.Cloneable

public class UniformDistribution
extends java.lang.Object
implements Distribution

A specification of a uniform random distribution.

See Also:
Serialized Form

Field Summary
protected  double high
           
protected  double low
           
 
Constructor Summary
UniformDistribution()
          Construct a UniformDistribution.
UniformDistribution(double low, double high)
          Creates new UniformDistribution
 
Method Summary
 java.lang.Object clone()
          Obtain a copy of this distribution.
 boolean equals(java.lang.Object other)
           
 int generateIntValue()
          Returns int value from low (inclusive) to high (exclusive).
 double generateValue()
          Generate a random value according to this distribution.
static void main(java.lang.String[] args)
           
static int[] pickDistinctIndices(int numToChoose, int low, int high)
           
static int pickIndex(int low, int high)
          Use a uniform distribution to pick a value between low (inclusive) and high (exclusive).
 void setParameters(double[] parameters)
          Set the parameters for this distribution.
 java.lang.String toString()
          Obtain a String representation of this distribution.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

low

protected double low

high

protected double high
Constructor Detail

UniformDistribution

public UniformDistribution()
Construct a UniformDistribution. Parameters must be set with setParameters().


UniformDistribution

public UniformDistribution(double low,
                           double high)
Creates new UniformDistribution

Method Detail

generateValue

public double generateValue()
Generate a random value according to this distribution.

Specified by:
generateValue in interface Distribution

generateIntValue

public int generateIntValue()
Returns int value from low (inclusive) to high (exclusive).

Specified by:
generateIntValue in interface Distribution

setParameters

public void setParameters(double[] parameters)
Set the parameters for this distribution. The first position in the array is the low value, and the second position is the high value.

Specified by:
setParameters in interface Distribution

pickIndex

public static int pickIndex(int low,
                            int high)
Use a uniform distribution to pick a value between low (inclusive) and high (exclusive). Useful for choosing an array position.


pickDistinctIndices

public static int[] pickDistinctIndices(int numToChoose,
                                        int low,
                                        int high)
Parameters:
low - int inclusive
high - int exclusive
Returns:
int[] Array of the chosen int indices, each distinct (no repeats)

toString

public java.lang.String toString()
Obtain a String representation of this distribution.

Specified by:
toString in interface Distribution
Overrides:
toString in class java.lang.Object

clone

public java.lang.Object clone()
Obtain a copy of this distribution.

Specified by:
clone in interface Distribution
Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

main

public static void main(java.lang.String[] args)