Class TwoCmres
- java.lang.Object
-
- org.apache.commons.rng.core.BaseProvider
-
- org.apache.commons.rng.core.source64.LongProvider
-
- org.apache.commons.rng.core.source64.TwoCmres
-
- All Implemented Interfaces:
RandomLongSource
,RestorableUniformRandomProvider
,UniformRandomProvider
public class TwoCmres extends LongProvider
Random number generator designed by Mark D. Overton.It is one of the many generators described by the author in the following article series:
- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
TwoCmres.Cmres
Subcycle generator.
-
Field Summary
Fields Modifier and Type Field Description private static TwoCmres.Cmres.Factory
FACTORY
Factory of instances of this class.private static java.lang.String
INTERNAL_ERROR_MSG
Error message.private static byte
SEED_GUARD
A small positive integer.private TwoCmres.Cmres
x
First subcycle generator.private long
xx
State of first subcycle generator.private TwoCmres.Cmres
y
Second subcycle generator.private long
yy
State of second subcycle generator.
-
Constructor Summary
Constructors Modifier Constructor Description private
TwoCmres(int seed, TwoCmres.Cmres x, TwoCmres.Cmres y)
Creates a new instance.TwoCmres(java.lang.Integer seed)
Creates a new instance.TwoCmres(java.lang.Integer seed, int i, int j)
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
getStateInternal()
Creates a snapshot of the RNG state.long
next()
static int
numberOfSubcycleGenerators()
private void
setSeedInternal(int seed)
protected void
setStateInternal(byte[] s)
Resets the RNG to the givenstate
.java.lang.String
toString()
-
Methods inherited from class org.apache.commons.rng.core.source64.LongProvider
nextBoolean, nextInt, nextLong, resetCachedState
-
Methods inherited from class org.apache.commons.rng.core.BaseProvider
checkIndex, checkStateSize, composeStateInternal, extendSeed, extendSeed, fillState, fillState, restoreState, saveState, splitStateInternal
-
-
-
-
Field Detail
-
INTERNAL_ERROR_MSG
private static final java.lang.String INTERNAL_ERROR_MSG
Error message.- See Also:
- Constant Field Values
-
SEED_GUARD
private static final byte SEED_GUARD
A small positive integer.- See Also:
- Constant Field Values
-
FACTORY
private static final TwoCmres.Cmres.Factory FACTORY
Factory of instances of this class. Singleton.
-
x
private final TwoCmres.Cmres x
First subcycle generator.
-
y
private final TwoCmres.Cmres y
Second subcycle generator.
-
xx
private long xx
State of first subcycle generator.
-
yy
private long yy
State of second subcycle generator.
-
-
Constructor Detail
-
TwoCmres
private TwoCmres(int seed, TwoCmres.Cmres x, TwoCmres.Cmres y)
Creates a new instance.- Parameters:
seed
- Initial seed.x
- First subcycle generator.y
- Second subcycle generator.- Throws:
java.lang.IllegalArgumentException
- ifx == y
.
-
TwoCmres
public TwoCmres(java.lang.Integer seed)
Creates a new instance.- Parameters:
seed
- Seed.
-
TwoCmres
public TwoCmres(java.lang.Integer seed, int i, int j)
Creates a new instance.- Parameters:
seed
- Seed.i
- Table entry for first subcycle generator.j
- Table entry for second subcycle generator.- Throws:
java.lang.IllegalArgumentException
- ifi == j
.java.lang.IndexOutOfBoundsException
- ifi < 0
ori >= numberOfSubcycleGenerators()
.java.lang.IndexOutOfBoundsException
- ifj < 0
orj >= numberOfSubcycleGenerators()
.
-
-
Method Detail
-
next
public long next()
- Returns:
- the next random value.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classBaseProvider
-
numberOfSubcycleGenerators
public static int numberOfSubcycleGenerators()
- Returns:
- the number of subcycle generators.
-
getStateInternal
protected byte[] getStateInternal()
Creates a snapshot of the RNG state.- Overrides:
getStateInternal
in classLongProvider
- Returns:
- the internal state.
-
setStateInternal
protected void setStateInternal(byte[] s)
Resets the RNG to the givenstate
.- Overrides:
setStateInternal
in classLongProvider
- Parameters:
s
- State (previously obtained by a call toBaseProvider.getStateInternal()
).- See Also:
BaseProvider.checkStateSize(byte[],int)
-
setSeedInternal
private void setSeedInternal(int seed)
- Parameters:
seed
- Seed.
-
-