org.encog.mathutil.randomize.generate
Class LinearCongruentialRandom
- java.lang.Object
-
- org.encog.mathutil.randomize.generate.AbstractGenerateRandom
-
- org.encog.mathutil.randomize.generate.AbstractBoxMuller
-
- org.encog.mathutil.randomize.generate.LinearCongruentialRandom
-
- All Implemented Interfaces:
- GenerateRandom
public class LinearCongruentialRandom extends AbstractBoxMuller
A Linear Congruential random number generator. A Linear Congruential Generator (LCG) yields a sequence of randomized numbers calculated with a linear equation. The method represents one of the oldest and best-known pseudorandom number generator algorithms. Most programming languages use this technique. http://en.wikipedia.org/wiki/Linear_congruential_generator/ Donald Knuth, The Art of Computer Programming, Volume 3, Section 3.2.1
-
-
Field Summary
Fields Modifier and Type Field and Description static longDEFAULT_INCDefault inc.static longDEFAULT_MOD1First part of default mod.static longDEFAULT_MOD2Second part of default mod.static longDEFAULT_MULTDefault mult.static longMAX_RANDThe maximum rand number that the standard GCC based LCG will generate.-
Fields inherited from class org.encog.mathutil.randomize.generate.AbstractBoxMuller
MU
-
-
Constructor Summary
Constructors Constructor and Description LinearCongruentialRandom()Constructor to use a seed equal to system time.LinearCongruentialRandom(long theSeed)Construct the default LCG.LinearCongruentialRandom(long theModulus, long theMultiplier, long theIncrement, long theSeed)Create a LCG with the specified modulus, multiplier and increment.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description longgetIncrement()longgetModulus()longgetMultiplier()longgetSeed()booleannextBoolean()doublenextDouble()floatnextFloat()intnextInt()longnextLong()-
Methods inherited from class org.encog.mathutil.randomize.generate.AbstractBoxMuller
nextGaussian
-
Methods inherited from class org.encog.mathutil.randomize.generate.AbstractGenerateRandom
nextDouble, nextDouble, nextInt, nextInt
-
-
-
-
Field Detail
-
DEFAULT_MOD1
public static final long DEFAULT_MOD1
First part of default mod.- See Also:
- Constant Field Values
-
DEFAULT_MOD2
public static final long DEFAULT_MOD2
Second part of default mod.- See Also:
- Constant Field Values
-
DEFAULT_MULT
public static final long DEFAULT_MULT
Default mult.- See Also:
- Constant Field Values
-
DEFAULT_INC
public static final long DEFAULT_INC
Default inc.- See Also:
- Constant Field Values
-
MAX_RAND
public static final long MAX_RAND
The maximum rand number that the standard GCC based LCG will generate.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LinearCongruentialRandom
public LinearCongruentialRandom(long theSeed)
Construct the default LCG. You need only specify a seed.- Parameters:
theSeed- The seed to use.
-
LinearCongruentialRandom
public LinearCongruentialRandom()
Constructor to use a seed equal to system time.
-
LinearCongruentialRandom
public LinearCongruentialRandom(long theModulus, long theMultiplier, long theIncrement, long theSeed)Create a LCG with the specified modulus, multiplier and increment. Unless you REALLY KNOW WHAT YOU ARE DOING, just use the constructor that just takes a seed. It will set these values to the same as set by the GCC C compiler. Setting these values wrong can create fairly useless random numbers.- Parameters:
theModulus- The modulus for the LCG algorithm.theMultiplier- The multiplier for the LCG algorithm.theIncrement- The increment for the LCG algorithm.theSeed- The seed for the LCG algorithm. Using the same seed will give the same random number sequence each time, whether in Java or DotNet.
-
-
Method Detail
-
getIncrement
public final long getIncrement()
- Returns:
- The LCG increment.
-
getModulus
public final long getModulus()
- Returns:
- The LCG modulus.
-
getMultiplier
public final long getMultiplier()
- Returns:
- The LCG multiplier.
-
getSeed
public final long getSeed()
- Returns:
- The current seed. Set to a constant to start, thereafter the previously generated random number.
-
nextDouble
public final double nextDouble()
- Returns:
- The next random number as a double between 0 and 1.
-
nextLong
public final long nextLong()
- Returns:
- The next random number as a long between 0 and MAX_RAND.
-
nextBoolean
public boolean nextBoolean()
- Returns:
- The next random boolean.
-
nextFloat
public float nextFloat()
- Returns:
- The next random floating point.
-
nextInt
public int nextInt()
- Returns:
- The next random integer.
-
-
DMelt 3.0 © DataMelt by jWork.ORG