inf.util
Class BiasedRandom

java.lang.Object
  extended by inf.util.BiasedRandom

public abstract class BiasedRandom
extends java.lang.Object

This class represents a source of randomness that, unlike java.util.Random, returns random numbers according to a non-uniform distribution. The random number generators provided by this class all use Random.nextDouble() as the underlying source of randomness. Only EXP10_0 incurs a significant performance overhead compared to the source.

Author:
Gerhard Wickler

Field Summary
static BiasedRandom EXP10_0
           A zero-biased source of random numbers.
static BiasedRandom LINEAR_0
           A zero-biased source of random numbers.
static BiasedRandom POLY2_0
           A zero-biased source of random numbers.
static BiasedRandom POLY4_0
           A zero-biased source of random numbers.
static BiasedRandom POLY8_0
           A zero-biased source of random numbers.
 
Constructor Summary
BiasedRandom()
           
 
Method Summary
abstract  double nextDouble()
           This function returns a biased random double from the range 0.0d (inclusive) to 1.0d (exclusive).
 int nextInt(int n)
           This function returns a biased random double int 0 and n-1 (both inclusive).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINEAR_0

public static final BiasedRandom LINEAR_0

A zero-biased source of random numbers. The numbers are biased towards 0 according a linear distribution.


POLY2_0

public static final BiasedRandom POLY2_0

A zero-biased source of random numbers. The numbers are biased towards 0 according a polynomial (degree 2) distribution.


POLY4_0

public static final BiasedRandom POLY4_0

A zero-biased source of random numbers. The numbers are biased towards 0 according a polynomial (degree 4) distribution.


POLY8_0

public static final BiasedRandom POLY8_0

A zero-biased source of random numbers. The numbers are biased towards 0 according a polynomial (degree 8) distribution.


EXP10_0

public static final BiasedRandom EXP10_0

A zero-biased source of random numbers. The numbers are biased towards 0 according a exponential distribution. Note: This random number generator is significantly slower than the polynomial ones and tends to be less biased than for example POLY8_0.

Constructor Detail

BiasedRandom

public BiasedRandom()
Method Detail

nextDouble

public abstract double nextDouble()

This function returns a biased random double from the range 0.0d (inclusive) to 1.0d (exclusive).

Returns:
a biased random double

nextInt

public int nextInt(int n)

This function returns a biased random double int 0 and n-1 (both inclusive).

Returns:
a biased random int