Class IntProvider
java.lang.Object
org.apache.commons.rng.core.BaseProvider
org.apache.commons.rng.core.source32.IntProvider
- All Implemented Interfaces:
RandomIntSource, RestorableUniformRandomProvider, UniformRandomProvider
- Direct Known Subclasses:
AbstractWell, DotyHumphreySmallFastCounting32, ISAACRandom, JDKRandom, JenkinsSmallFast32, KISSRandom, L32X64Mix, MersenneTwister, MiddleSquareWeylSequence, MultiplyWithCarry256, PcgMcgXshRr32, PcgMcgXshRs32, PcgXshRr32, PcgXshRs32, XoRoShiRo64Star, XoRoShiRo64StarStar, XoShiRo128Plus, XoShiRo128PlusPlus, XoShiRo128StarStar
Base class for all implementations that provide an
int-based
source randomness.-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new instance.protectedIntProvider(IntProvider source) Creates a new instance copying the state from the source. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]Creates a snapshot of the RNG state.booleanGenerates abooleanvalue.voidnextBytes(byte[] bytes) Generatesbytevalues and places them into a user-supplied array.voidnextBytes(byte[] bytes, int start, int len) Generatesbytevalues and places them into a user-supplied array.doubleGenerates adoublevalue between 0 (inclusive) and 1 (exclusive).intnextInt()Generates anintvalue.longnextLong()Generates alongvalue.protected voidReset the cached state used in the default implementation ofnextBoolean().protected voidsetStateInternal(byte[] s) Resets the RNG to the givenstate.Methods inherited from class BaseProvider
checkIndex, checkStateSize, composeStateInternal, extendSeed, extendSeed, fillState, fillState, restoreState, saveState, splitStateInternal, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface RandomIntSource
next
-
Constructor Details
-
IntProvider
public IntProvider()Creates a new instance. -
IntProvider
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
JumpableUniformRandomProviderinterface.- Parameters:
source- Source to copy.- Since:
- 1.3
-
-
Method Details
-
resetCachedState
Reset the cached state used in the default implementation ofnextBoolean().This should be used when the state is no longer valid, for example after a jump performed for the
JumpableUniformRandomProviderinterface.- Since:
- 1.3
-
getStateInternal
Creates a snapshot of the RNG state.- Overrides:
getStateInternalin classBaseProvider- Returns:
- the internal state.
-
setStateInternal
Resets the RNG to the givenstate.- Overrides:
setStateInternalin classBaseProvider- Parameters:
s- State (previously obtained by a call toBaseProvider.getStateInternal()).- See Also:
-
nextInt
Generates anintvalue.- Specified by:
nextIntin interfaceUniformRandomProvider- Returns:
- the next random value.
-
nextBoolean
Generates abooleanvalue.- Specified by:
nextBooleanin interfaceUniformRandomProvider- Returns:
- the next random value.
-
nextDouble
Generates adoublevalue between 0 (inclusive) and 1 (exclusive).- Specified by:
nextDoublein interfaceUniformRandomProvider- Returns:
- the next random value between 0 (inclusive) and 1 (exclusive).
-
nextLong
Generates alongvalue.- Specified by:
nextLongin interfaceUniformRandomProvider- Returns:
- the next random value.
-
nextBytes
Generatesbytevalues and places them into a user-supplied array.The number of random bytes produced is equal to the length of the byte array.
- Specified by:
nextBytesin interfaceUniformRandomProvider- Parameters:
bytes- Byte array in which to put the random bytes. Cannot benull.
-
nextBytes
Generatesbytevalues and places them into a user-supplied array.The array is filled with bytes extracted from random integers. This implies that the number of random bytes generated may be larger than the length of the byte array.
- Specified by:
nextBytesin interfaceUniformRandomProvider- Parameters:
bytes- Array in which to put the generated bytes. Cannot benull.start- Index at which to start inserting the generated bytes.len- Number of bytes to insert.
-