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
abstract class AbstractPcgMcg6432 extends IntProvider
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:
- PCG, A Family of Better Random Number Generators
-
-
Field Summary
Fields Modifier and Type Field Description private long
state
The state of the MCG.
-
Constructor Summary
Constructors Constructor Description AbstractPcgMcg6432(java.lang.Long seed)
Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static long
bump(long input)
Provides the next state of the MCG.protected byte[]
getStateInternal()
Creates a snapshot of the RNG state.int
next()
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
-
-
-
-
Method Detail
-
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()
- 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:
BaseProvider.checkStateSize(byte[],int)
-
-