org.jgap.util
Class randomLCG
- java.lang.Object
-
- org.jgap.util.randomX
-
- org.jgap.util.randomLCG
-
public class randomLCG extends randomX
Implementation of a randomX-compliant class using the simple (and not very good) rand() linear congruential generator given as an example in the ANSI C specification. This is intended not for serious use, merely as an illustration of a simple software-based randomX generator.The generation algorithm is:
Ij+1 = (Ijx1103515245+12345) & 0x7FFFFFFF Designed and implemented in July 1996 by John Walker, kelvin@fourmilab.ch.
-
-
Constructor Summary
Constructors Constructor and Description randomLCG()Creates a new pseudorandom number generator, seeded from the current time.randomLCG(long seed)Creates a new pseudorandom number generator with a specified seed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description bytenextByte()Get next byte from generator.voidsetSeed(long seed)Set seed for generator.
-
-
-
Constructor Detail
-
randomLCG
public randomLCG()
Creates a new pseudorandom number generator, seeded from the current time.
-
randomLCG
public randomLCG(long seed)
Creates a new pseudorandom number generator with a specified seed.- Parameters:
seed- initial seed for the generator
-
-
Method Detail
-
setSeed
public void setSeed(long seed)
Set seed for generator. Subsequent values will be based on the given seed.- Parameters:
seed- seed for the generator
-
nextByte
public byte nextByte()
Get next byte from generator. Given how poor this generator is, it's wise to make a separate call for each byte rather than extract fields from a single call, which may be correlated. Also, the higher-order bits of this generator are more random than the low, so we extract the byte after discarding the low-order 11 bits.
-
-
DMelt 3.0 © DataMelt by jWork.ORG