Class AbstractPcgMcg6432
java.lang.Object
org.apache.commons.rng.core.BaseProvider
org.apache.commons.rng.core.source32.IntProvider
org.apache.commons.rng.core.source32.AbstractPcgMcg6432
- All Implemented Interfaces:
RandomIntSource
,RestorableUniformRandomProvider
,UniformRandomProvider
- Direct Known Subclasses:
PcgMcgXshRr32
,PcgMcgXshRs32
This abstract class is a base for algorithms from the Permuted Congruential Generator (PCG)
family that use an internal 64-bit Multiplicative Congruential Generator (MCG) and output
32-bits per cycle.
- Since:
- 1.3
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static long
bump
(long input) Provides the next state of the MCG.protected byte[]
Creates a snapshot of the RNG state.int
next()
Return the next random value.protected void
setStateInternal
(byte[] s) Resets the RNG to the givenstate
.protected abstract int
transform
(long x) Transform the 64-bit state of the generator to a 32-bit output.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 Details
-
state
private long stateThe state of the MCG.
-
-
Constructor Details
-
AbstractPcgMcg6432
AbstractPcgMcg6432(Long seed) Creates a new instance.- Parameters:
seed
- Initial seed.
-
-
Method Details
-
bump
private static long bump(long input) Provides the next state of the MCG.- Parameters:
input
- Current state.- Returns:
- next state
-
next
public int next()Return the next random value.- Returns:
- the next random value.
-
transform
protected abstract int transform(long x) 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
-
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:
-