Package org.uncommons.maths.random
Class CellularAutomatonRNG
- java.lang.Object
-
- java.util.Random
-
- org.uncommons.maths.random.CellularAutomatonRNG
-
- All Implemented Interfaces:
java.io.Serializable
,RepeatableRNG
public class CellularAutomatonRNG extends java.util.Random implements RepeatableRNG
Java port of the cellular automaton pseudorandom number generator developed by Tony Pasqualoni.
NOTE: Instances of this class do not use the seeding mechanism inherited from
Random
. Calls to theRandom.setSeed(long)
method will have no effect. Instead the seed must be set by a constructor.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static int
AUTOMATON_LENGTH
private int[]
cells
private int
currentCellIndex
private java.util.concurrent.locks.ReentrantLock
lock
private static int[]
RNG_RULE
private byte[]
seed
private static int
SEED_SIZE_BYTES
-
Constructor Summary
Constructors Constructor Description CellularAutomatonRNG()
Creates a new RNG and seeds it using the default seeding strategy.CellularAutomatonRNG(byte[] seed)
Creates an RNG and seeds it with the specified seed data.CellularAutomatonRNG(SeedGenerator seedGenerator)
Seed the RNG using the provided seed generation strategy.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static int
convertCellsToInt(int[] cells, int offset)
byte[]
getSeed()
int
next(int bits)
-
-
-
Field Detail
-
SEED_SIZE_BYTES
private static final int SEED_SIZE_BYTES
- See Also:
- Constant Field Values
-
AUTOMATON_LENGTH
private static final int AUTOMATON_LENGTH
- See Also:
- Constant Field Values
-
RNG_RULE
private static final int[] RNG_RULE
-
seed
private final byte[] seed
-
cells
private final int[] cells
-
lock
private final java.util.concurrent.locks.ReentrantLock lock
-
currentCellIndex
private int currentCellIndex
-
-
Constructor Detail
-
CellularAutomatonRNG
public CellularAutomatonRNG()
Creates a new RNG and seeds it using the default seeding strategy.
-
CellularAutomatonRNG
public CellularAutomatonRNG(SeedGenerator seedGenerator) throws SeedException
Seed the RNG using the provided seed generation strategy.- Parameters:
seedGenerator
- The seed generation strategy that will provide the seed value for this RNG.- Throws:
SeedException
- If there is a problem generating a seed.
-
CellularAutomatonRNG
public CellularAutomatonRNG(byte[] seed)
Creates an RNG and seeds it with the specified seed data.- Parameters:
seed
- The seed data used to initialise the RNG.
-
-
Method Detail
-
next
public int next(int bits)
- Overrides:
next
in classjava.util.Random
-
getSeed
public byte[] getSeed()
- Specified by:
getSeed
in interfaceRepeatableRNG
- Returns:
- The seed data used to initialise this pseudo-random number generator.
-
convertCellsToInt
private static int convertCellsToInt(int[] cells, int offset)
-
-