Class LongProvider
java.lang.Object
org.apache.commons.rng.core.BaseProvider
org.apache.commons.rng.core.source64.LongProvider
- All Implemented Interfaces:
RandomLongSource
,RestorableUniformRandomProvider
,UniformRandomProvider
- Direct Known Subclasses:
AbstractL128
,AbstractL64
,AbstractXoRoShiRo1024
,AbstractXoRoShiRo128
,AbstractXoShiRo256
,AbstractXoShiRo512
,DotyHumphreySmallFastCounting64
,JenkinsSmallFast64
,MersenneTwister64
,PcgRxsMXs64
,SplitMix64
,TwoCmres
,XorShift1024Star
Base class for all implementations that provide a
long
-based
source randomness.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
Provides a bit source for booleans.private static final long
Empty boolean source.private static final long
Empty int source.private long
Provides a source for ints. -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new instance.protected
LongProvider
(LongProvider source) Creates a new instance copying the state from the source. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]
Creates a snapshot of the RNG state.boolean
Generates aboolean
value.int
nextInt()
Generates anint
value.long
nextLong()
Generates along
value.protected void
Reset the cached state used in the default implementation ofnextBoolean()
andnextInt()
.protected void
setStateInternal
(byte[] s) Resets the RNG to the givenstate
.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.core.source64.RandomLongSource
next
-
Field Details
-
EMPTY_BOOL_SOURCE
private static final long EMPTY_BOOL_SOURCEEmpty boolean source. This is the location of the sign-bit after 63 right shifts on the boolean source.- See Also:
-
EMPTY_INT_SOURCE
private static final long EMPTY_INT_SOURCEEmpty int source. This requires a negative value as the sign-bit is used to trigger a refill.- See Also:
-
booleanSource
private long booleanSourceProvides a bit source for booleans.A cached value from a call to
RandomLongSource.next()
.Only stores 63-bits when full as 1 bit has already been consumed. The sign bit is a flag that shifts down so the source eventually equals 1 when all bits are consumed and will trigger a refill.
-
intSource
private long intSourceProvides a source for ints.A cached half-value value from a call to
RandomLongSource.next()
. The int is stored in the lower 32 bits with zeros in the upper bits. When empty this is set to negative to trigger a refill.
-
-
Constructor Details
-
LongProvider
public LongProvider()Creates a new instance. -
LongProvider
Creates a new instance copying the state from the source.This provides base functionality to allow a generator to create a copy, for example for use in the
JumpableUniformRandomProvider
interface.- Parameters:
source
- Source to copy.- Since:
- 1.3
-
-
Method Details
-
resetCachedState
protected void resetCachedState()Reset the cached state used in the default implementation ofnextBoolean()
andnextInt()
.This should be used when the state is no longer valid, for example after a jump performed for the
JumpableUniformRandomProvider
interface.- Since:
- 1.3
-
getStateInternal
protected byte[] getStateInternal()Creates a snapshot of the RNG state.- Overrides:
getStateInternal
in classBaseProvider
- Returns:
- the internal state.
-
setStateInternal
protected void setStateInternal(byte[] s) Resets the RNG to the givenstate
.- Overrides:
setStateInternal
in classBaseProvider
- Parameters:
s
- State (previously obtained by a call toBaseProvider.getStateInternal()
).- See Also:
-
nextLong
public long nextLong()Generates along
value.- Specified by:
nextLong
in interfaceUniformRandomProvider
- Returns:
- the next random value.
-
nextInt
public int nextInt()Generates anint
value.- Specified by:
nextInt
in interfaceUniformRandomProvider
- Returns:
- the next random value.
-
nextBoolean
public boolean nextBoolean()Generates aboolean
value.- Specified by:
nextBoolean
in interfaceUniformRandomProvider
- Returns:
- the next random value.
-