Class AbstractL128
- java.lang.Object
-
- org.apache.commons.rng.core.BaseProvider
-
- org.apache.commons.rng.core.source64.LongProvider
-
- org.apache.commons.rng.core.source64.AbstractL128
-
- All Implemented Interfaces:
RandomLongSource
,JumpableUniformRandomProvider
,LongJumpableUniformRandomProvider
,RestorableUniformRandomProvider
,UniformRandomProvider
- Direct Known Subclasses:
L128X1024Mix
,L128X128Mix
,L128X256Mix
abstract class AbstractL128 extends LongProvider implements LongJumpableUniformRandomProvider
This abstract class is a base for algorithms from the LXM family of generators with a 128-bit LCG sub-generator. The class implements the jump functions.- Since:
- 1.5
-
-
Field Summary
Fields Modifier and Type Field Description protected long
lah
High half of the 128-bit per-instance LCG additive parameter.protected long
lal
Low half of the 128-bit per-instance LCG additive parameter (must be odd).protected long
lsh
High half of the 128-bit state of the LCG generator.protected long
lsl
Low half of the 128-bit state of the LCG generator.private static long
ML
Low half of 128-bit LCG multiplier.private static int
SEED_SIZE
Size of the seed vector.
-
Constructor Summary
Constructors Constructor Description AbstractL128(long[] seed)
Creates a new instance.AbstractL128(long seed0, long seed1, long seed2, long seed3)
Creates a new instance using a 4 element seed.AbstractL128(AbstractL128 source)
Creates a copy instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract AbstractL128
copy()
Create a copy.protected byte[]
getStateInternal()
Creates a snapshot of the RNG state.UniformRandomProvider
jump()
Creates a copy of the UniformRandomProvider and then retreats the state of the current instance.JumpableUniformRandomProvider
longJump()
Creates a copy of the UniformRandomProvider and then retreats the state of the current instance.private void
setState(long[] state)
Copies the state into the generator state.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
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.rng.JumpableUniformRandomProvider
jumps, jumps
-
Methods inherited from interface org.apache.commons.rng.LongJumpableUniformRandomProvider
longJumps, longJumps
-
Methods inherited from interface org.apache.commons.rng.core.source64.RandomLongSource
next
-
Methods inherited from interface org.apache.commons.rng.UniformRandomProvider
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextBytes, nextBytes, nextDouble, nextDouble, nextDouble, nextFloat, nextFloat, nextFloat, nextInt, nextInt, nextInt, nextLong, nextLong, nextLong
-
-
-
-
Field Detail
-
SEED_SIZE
private static final int SEED_SIZE
Size of the seed vector.- See Also:
- Constant Field Values
-
ML
private static final long ML
Low half of 128-bit LCG multiplier.- See Also:
- Constant Field Values
-
lah
protected long lah
High half of the 128-bit per-instance LCG additive parameter. Cannot be final to support RestorableUniformRandomProvider.
-
lal
protected long lal
Low half of the 128-bit per-instance LCG additive parameter (must be odd). Cannot be final to support RestorableUniformRandomProvider.
-
lsh
protected long lsh
High half of the 128-bit state of the LCG generator.
-
lsl
protected long lsl
Low half of the 128-bit state of the LCG generator.
-
-
Constructor Detail
-
AbstractL128
AbstractL128(long[] seed)
Creates a new instance.- Parameters:
seed
- Initial seed. If the length is larger than 4, only the first 4 elements will be used; if smaller, the remaining elements will be automatically set.The 1st and 2nd elements are used to set the LCG increment; the least significant bit is set to odd to ensure a full period LCG. The 3rd and 4th elements are used to set the LCG state.
-
AbstractL128
AbstractL128(long seed0, long seed1, long seed2, long seed3)
Creates a new instance using a 4 element seed.The 1st and 2nd elements are used to set the LCG increment; the least significant bit is set to odd to ensure a full period LCG. The 3rd and 4th elements are used to set the LCG state.
- Parameters:
seed0
- Initial seed element 0.seed1
- Initial seed element 1.seed2
- Initial seed element 2.seed3
- Initial seed element 3.
-
AbstractL128
AbstractL128(AbstractL128 source)
Creates a copy instance.- Parameters:
source
- Source to copy.
-
-
Method Detail
-
setState
private void setState(long[] state)
Copies the state into the generator state.- Parameters:
state
- the new state
-
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:
BaseProvider.checkStateSize(byte[],int)
-
jump
public UniformRandomProvider jump()
Creates a copy of the UniformRandomProvider and then retreats the state of the current instance. The copy is returned.The jump is performed by advancing the state of the LCG sub-generator by 1 cycle. The XBG state is unchanged.
- Specified by:
jump
in interfaceJumpableUniformRandomProvider
- Returns:
- A copy of the current state.
-
longJump
public JumpableUniformRandomProvider longJump()
Creates a copy of the UniformRandomProvider and then retreats the state of the current instance. The copy is returned.The jump is performed by advancing the state of the LCG sub-generator by 264 cycles. The XBG state is unchanged.
- Specified by:
longJump
in interfaceLongJumpableUniformRandomProvider
- Returns:
- A copy of the current state.
-
copy
abstract AbstractL128 copy()
Create a copy.- Returns:
- the copy
-
-