Class PcgXshRr32
java.lang.Object
org.apache.commons.rng.core.BaseProvider
org.apache.commons.rng.core.source32.IntProvider
org.apache.commons.rng.core.source32.PcgXshRr32
- All Implemented Interfaces:
RandomIntSource, RestorableUniformRandomProvider, UniformRandomProvider
A Permuted Congruential Generator (PCG) that is composed of a 64-bit Linear Congruential
Generator (LCG) combined with the XSH-RR (xorshift; random rotate) output
transformation to create 32-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:
-
Constructor Summary
ConstructorsConstructorDescriptionPcgXshRr32(long[] seed) Creates a new instance.PcgXshRr32(Long seed) Creates a new instance using a default increment. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]Creates a snapshot of the RNG state.intnext()Return the next random value.protected voidsetStateInternal(byte[] s) Resets the RNG to the givenstate.protected inttransform(long x) Transform the 64-bit state of the generator to a 32-bit output.Methods inherited from class IntProvider
nextBoolean, nextBytes, nextBytes, nextDouble, nextInt, nextLong, resetCachedStateMethods inherited from class BaseProvider
checkIndex, checkStateSize, composeStateInternal, extendSeed, extendSeed, fillState, fillState, restoreState, saveState, splitStateInternal, toString
-
Constructor Details
-
PcgXshRr32
Creates a new instance using a default increment.- Parameters:
seed- Initial state.- Since:
- 1.4
-
PcgXshRr32
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
-
transform
Transform the 64-bit state of the generator to a 32-bit output. The transformation function shall vary with respect to different generators.- Parameters:
x- State.- Returns:
- the output
-
next
public int next()Return the next random value.- Returns:
- the next random value.
-
getStateInternal
protected byte[] getStateInternal()Creates a snapshot of the RNG state.- Overrides:
getStateInternalin classIntProvider- Returns:
- the internal state.
-
setStateInternal
protected void setStateInternal(byte[] s) Resets the RNG to the givenstate.- Overrides:
setStateInternalin classIntProvider- Parameters:
s- State (previously obtained by a call toBaseProvider.getStateInternal()).- See Also:
-