unlekker.util
Class Rnd

java.lang.Object
  extended by ec.util.MersenneTwisterFast
      extended by unlekker.util.Rnd
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Rnd
extends MersenneTwisterFast
implements java.io.Serializable

unlekker.util.Rnd provides an alternative to java.util.rand by wrapping ec.util.MersenneTwisterFast in a Processing-friendly convenience class.

Mersenne Twister is an advanced pseudo-random number generator with a period of 2^19937-1. The code used here is from Sean Luke, and is part of his ECJ Evolutionary Computation Research System.

Author:
Marius Watz
See Also:
Serialized Form

Constructor Summary
Rnd()
          Initialize rand number generator.
Rnd(long seed)
           
 
Method Summary
 float rand()
          Returns a rand value in the ranges [0..1>, [0..range> or [min..max> depending on the version used.
 float rand(float range)
           
 float rand(float min, float max)
           
 boolean randBool()
          Randomly returns true or false.
 int randInt(int range)
          Returns a rand integer value in the range [0..range-1> or [min..max-1>.
 int randInt(int min, int max)
           
 boolean randProb(double chance)
          Returns true if rndFloat(100) returns a result greater than the parameter "chance".
 
Methods inherited from class ec.util.MersenneTwisterFast
clone, main, nextBoolean, nextBoolean, nextBoolean, nextByte, nextBytes, nextChar, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, nextLong, nextShort, readState, setSeed, setSeed, stateEquals, writeState
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rnd

public Rnd()
Initialize rand number generator. When called the first time the seed 0 will be used. An internal static variable is then incremented, so that the next instance will have seed 1 etc.


Rnd

public Rnd(long seed)
Method Detail

randBool

public boolean randBool()
Randomly returns true or false.

Returns:
boolean

randProb

public boolean randProb(double chance)
Returns true if rndFloat(100) returns a result greater than the parameter "chance".

Parameters:
chance - double
Returns:
boolean

rand

public float rand()
Returns a rand value in the ranges [0..1>, [0..range> or [min..max> depending on the version used.

Returns:
float

rand

public float rand(float range)

rand

public float rand(float min,
                  float max)

randInt

public int randInt(int range)
Returns a rand integer value in the range [0..range-1> or [min..max-1>.

Parameters:
range -
Returns:
int

randInt

public int randInt(int min,
                   int max)