Class PcgRxsMXs64
java.lang.Object
org.apache.commons.rng.core.BaseProvider
org.apache.commons.rng.core.source64.LongProvider
org.apache.commons.rng.core.source64.PcgRxsMXs64
- All Implemented Interfaces:
RandomLongSource
,RestorableUniformRandomProvider
,UniformRandomProvider
A Permuted Congruential Generator (PCG) that is composed of a 64-bit Linear Congruential
Generator (LCG) combined with the RXS-M-XS (random xorshift; multiply; xorshift) output
transformation to create 64-bit output.
State size is 128 bits and the period is 264.
Note: Although the seed size is 128 bits, only the first 64 are effective: in effect, two seeds that only differ by the last 64 bits may produce highly correlated sequences.
- Since:
- 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
The default increment.private long
The increment of the LCG.private static final int
Size of the seed array.private long
The state of the LCG. -
Constructor Summary
ConstructorsConstructorDescriptionPcgRxsMXs64
(long[] seed) Creates a new instance.PcgRxsMXs64
(Long seed) Creates a new instance using a default increment. -
Method Summary
Modifier and TypeMethodDescriptionprivate long
bump
(long input) Provides the next state of the LCG.protected byte[]
Creates a snapshot of the RNG state.long
next()
private void
setSeedInternal
(long[] seed) Seeds the RNG.protected void
setStateInternal
(byte[] s) Resets the RNG to the givenstate
.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, toString
-
Field Details
-
SEED_SIZE
private static final int SEED_SIZESize of the seed array.- See Also:
-
DEFAULT_INCREMENT
private static final long DEFAULT_INCREMENTThe default increment.- See Also:
-
state
private long stateThe state of the LCG. -
increment
private long incrementThe increment of the LCG.
-
-
Constructor Details
-
PcgRxsMXs64
Creates a new instance using a default increment.- Parameters:
seed
- Initial state.- Since:
- 1.4
-
PcgRxsMXs64
public PcgRxsMXs64(long[] seed) Creates a new instance.Note: Although the seed size is 128 bits, only the first 64 are effective: in effect, two seeds that only differ by the last 64 bits may produce highly correlated sequences.
- Parameters:
seed
- Initial seed. If the length is larger than 2, only the first 2 elements will be used; if smaller, the remaining elements will be automatically set.The 1st element is used to set the LCG state. The 2nd element is used to set the LCG increment; the most significant bit is discarded by left shift and the increment is set to odd.
-
-
Method Details
-
setSeedInternal
private void setSeedInternal(long[] seed) Seeds the RNG.- Parameters:
seed
- Seed.
-
bump
private long bump(long input) Provides the next state of the LCG.- Parameters:
input
- Current state.- Returns:
- next state
-
next
public long next()- Returns:
- the next random value.
-
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:
-