unlekker.util
Class Rnd

java.lang.Object
  extended by unlekker.util.Rnd
All Implemented Interfaces:
java.io.Serializable

public class Rnd
extends java.lang.Object
implements java.io.Serializable

unlekker.Rnd implements the Mersenne Twister, an advanced psuedorandom number generator with a period of 2^19937-1. It is an adaptation of Paul Houle's RngPack library.

See Also:
Serialized Form

Constructor Summary
Rnd()
          Initialize random number generator.
Rnd(long seed)
           
 
Method Summary
 boolean probGt(float chance)
          Returns true if rndFloat(100) returns a result greater than the parameter "chance".
 float random()
          Returns a random value in the ranges [0..1>, [0..range> or [min..max> depending on the version used.
 float random(float range)
           
 float random(float min, float max)
           
 boolean randomBool()
          Randomly returns true or false.
 int randomInt(int range)
          Returns a random integer value in the range [0..range-1> or [min..max-1>.
 int randomInt(int min, int max)
           
 void randomSeed(long _seed)
           
 void randomSeedComplex(int[] array)
          Paul Houle: An alternative, more complete, method of seeding the pseudo random number generator.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Rnd

public Rnd()
Initialize random 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

randomSeed

public void randomSeed(long _seed)

randomSeedComplex

public void randomSeedComplex(int[] array)
Paul Houle: An alternative, more complete, method of seeding the pseudo random number generator. array must be an array of 624 ints, and they can be any value as long as they're not *all* zero.


randomBool

public boolean randomBool()
Randomly returns true or false.

Returns:
boolean

probGt

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

Parameters:
chance - float
Returns:
boolean

random

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

Returns:
float

random

public float random(float range)

random

public float random(float min,
                    float max)

randomInt

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

Parameters:
min - int
max - int
Returns:
int

randomInt

public int randomInt(int min,
                     int max)