Class MultiplyWithCarry256
- java.lang.Object
-
- org.apache.commons.rng.core.BaseProvider
-
- org.apache.commons.rng.core.source32.IntProvider
-
- org.apache.commons.rng.core.source32.MultiplyWithCarry256
-
- All Implemented Interfaces:
RandomIntSource
,RestorableUniformRandomProvider
,UniformRandomProvider
public class MultiplyWithCarry256 extends IntProvider
Port from Marsaglia's "Multiply-With-Carry" algorithm.Implementation is based on the (non-portable!) C code reproduced on that page.
- Since:
- 1.0
- See Also:
- Multiply with carry (Wikipedia)
-
-
Constructor Summary
Constructors Constructor Description MultiplyWithCarry256(int[] seed)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
getStateInternal()
Creates a snapshot of the RNG state.int
next()
private void
setSeedInternal(int[] seed)
Seeds the RNG.protected void
setStateInternal(byte[] s)
Resets the RNG to the givenstate
.-
Methods inherited from class org.apache.commons.rng.core.source32.IntProvider
nextBoolean, nextBytes, nextBytes, nextBytesFill, nextDouble, nextInt, nextLong, resetCachedState
-
Methods inherited from class org.apache.commons.rng.core.BaseProvider
checkIndex, checkStateSize, composeStateInternal, extendSeed, extendSeed, fillState, fillState, restoreState, saveState, splitStateInternal, toString
-
-
-
-
Field Detail
-
Q_SIZE
private static final int Q_SIZE
Length of the state array.- See Also:
- Constant Field Values
-
SEED_SIZE
private static final int SEED_SIZE
Size of the seed.- See Also:
- Constant Field Values
-
A
private static final long A
Multiply.- See Also:
- Constant Field Values
-
state
private final int[] state
State.
-
index
private int index
Current index in "state" array.
-
carry
private int carry
Carry.
-
-
Method Detail
-
getStateInternal
protected byte[] getStateInternal()
Creates a snapshot of the RNG state.- Overrides:
getStateInternal
in classIntProvider
- Returns:
- the internal state.
-
setStateInternal
protected void setStateInternal(byte[] s)
Resets the RNG to the givenstate
.- Overrides:
setStateInternal
in classIntProvider
- Parameters:
s
- State (previously obtained by a call toBaseProvider.getStateInternal()
).- See Also:
BaseProvider.checkStateSize(byte[],int)
-
setSeedInternal
private void setSeedInternal(int[] seed)
Seeds the RNG.- Parameters:
seed
- Seed.
-
next
public int next()
- Returns:
- the next random value.
-
-