Class Philox4x32
- All Implemented Interfaces:
ArbitrarilyJumpableUniformRandomProvider,RandomIntSource,JumpableUniformRandomProvider,LongJumpableUniformRandomProvider,RestorableUniformRandomProvider,UniformRandomProvider
This is a member of the Philox family of generators. Memory footprint is 192 bits and the period is 2130.
Jumping in the sequence is essentially instantaneous. This generator provides both subsequences and arbitrary jumps for easy parallelization.
References:
- Salmon, J.K. et al (2011) Parallel Random Numbers: As Easy as 1,2,3.
- Since:
- 1.7
-
Constructor Summary
ConstructorsConstructorDescriptionPhilox4x32(int[] seed) Creates a new instance based on an array of int containing, key (first two ints) and the counter (next 4 ints, low bits = first int). -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]Creates a snapshot of the RNG state.jump()Creates a copy of the UniformRandomProvider and then advances the state of the current instance.jump(double distance) Creates a copy of theArbitrarilyJumpableUniformRandomProviderand then advances the state cycle of the current instance by the specifieddistance.jumpPowerOfTwo(int logDistance) Creates a copy of theArbitrarilyJumpableUniformRandomProviderand then advances the state cycle of the current instance by a distance equal to 2logDistance.jumps(double distance) Returns an effectively unlimited stream of new random generators, each of which implements theArbitrarilyJumpableUniformRandomProviderinterface.longJump()Creates a copy of the JumpableUniformRandomProvider and then advances the state of the current instance.intnext()Return the next random value.protected voidsetStateInternal(byte[] s) Resets the RNG to the givenstate.Methods inherited from class org.apache.commons.rng.core.source32.IntProvider
nextBoolean, nextBytes, nextBytes, nextDouble, nextInt, nextLong, resetCachedStateMethods inherited from class org.apache.commons.rng.core.BaseProvider
checkIndex, checkStateSize, composeStateInternal, extendSeed, extendSeed, fillState, fillState, restoreState, saveState, splitStateInternal, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.rng.ArbitrarilyJumpableUniformRandomProvider
jumpsMethods inherited from interface org.apache.commons.rng.JumpableUniformRandomProvider
jumps, jumpsMethods inherited from interface org.apache.commons.rng.LongJumpableUniformRandomProvider
longJumps, longJumpsMethods 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
-
Constructor Details
-
Philox4x32
Creates a new instance based on an array of int containing, key (first two ints) and the counter (next 4 ints, low bits = first int). The counter is not scrambled and may be used to create contiguous blocks with size a multiple of 4 ints. For example, setting seed[2] = 1 is equivalent to start with seed[2]=0 and callingnext()4 times.- Parameters:
seed- Array of size 6 defining key0,key1,counter0,counter1,counter2,counter3. If the size is smaller, zero values are assumed.
-
-
Method Details
-
getStateInternal
Creates a snapshot of the RNG state.- Overrides:
getStateInternalin classIntProvider- Returns:
- the internal state.
-
setStateInternal
Resets the RNG to the givenstate.- Overrides:
setStateInternalin classIntProvider- Parameters:
s- State (previously obtained by a call toBaseProvider.getStateInternal()).- See Also:
-
next
Return the next random value.- Specified by:
nextin interfaceRandomIntSource- Returns:
- the next random value.
-
jump
Creates a copy of the UniformRandomProvider and then advances the state of the current instance. The copy is returned.The current state will be advanced in a single operation by the equivalent of a number of sequential calls to a method that updates the state of the provider. The size of the jump is implementation dependent.
Repeat invocations of this method will create a series of generators that are uniformly spaced at intervals of the output sequence. Each generator provides non-overlapping output for the length of the jump for use in parallel computations.
The jump size is the equivalent of 266 calls to
nextInt(). It can provide up to 264 non-overlapping subsequences.- Specified by:
jumpin interfaceJumpableUniformRandomProvider- Returns:
- A copy of the current state.
-
longJump
Creates a copy of the JumpableUniformRandomProvider and then advances the state of the current instance. The copy is returned.The current state will be advanced in a single operation by the equivalent of a number of sequential calls to a method that updates the state of the provider. The size of the long jump is implementation dependent.
Repeat invocations of this method will create a series of generators that are uniformly spaced at intervals of the output sequence. Each generator provides non-overlapping output for the length of the long jump for use in parallel computations.
The returned copy may be jumped
m / ntimes before overlap with the current instance wheremis the long jump length andnis the jump length of theJumpableUniformRandomProvider.jump()method.The jump size is the equivalent of 298 calls to
nextLong(). It can provide up to 232 non-overlapping subsequences of length 298; each subsequence can provide up to 232 non-overlapping subsequences of length 266 using thejump()method.- Specified by:
longJumpin interfaceLongJumpableUniformRandomProvider- Returns:
- A copy of the current state.
-
jump
Creates a copy of theArbitrarilyJumpableUniformRandomProviderand then advances the state cycle of the current instance by the specifieddistance. The copy is returned.The current state will be advanced in a single operation by the equivalent of a number of sequential calls to a method that updates the state cycle of the provider.
Repeat invocations of this method will create a series of generators that are uniformly spaced at intervals of the output sequence. Each generator provides non-overlapping output for the length specified by
distancefor use in parallel computations.- Specified by:
jumpin interfaceArbitrarilyJumpableUniformRandomProvider- Parameters:
distance- Distance to jump forward with the state cycle.- Returns:
- A copy of the current state.
-
jumpPowerOfTwo
Creates a copy of theArbitrarilyJumpableUniformRandomProviderand then advances the state cycle of the current instance by a distance equal to 2logDistance. The copy is returned.The current state will be advanced in a single operation by the equivalent of a number of sequential calls to a method that updates the state cycle of the provider.
Repeat invocations of this method will create a series of generators that are uniformly spaced at intervals of the output sequence. Each generator provides non-overlapping output for the length specified by 2
logDistancefor use in parallel computations.- Specified by:
jumpPowerOfTwoin interfaceArbitrarilyJumpableUniformRandomProvider- Parameters:
logDistance- Base-2 logarithm of the distance to jump forward with the state cycle.- Returns:
- A copy of the current state.
-
jumps
Returns an effectively unlimited stream of new random generators, each of which implements theArbitrarilyJumpableUniformRandomProviderinterface. The generators are output at integer multiples of the specified jumpdistancein the generator's state cycle.- Specified by:
jumpsin interfaceArbitrarilyJumpableUniformRandomProvider- Parameters:
distance- Distance to jump forward with the state cycle.- Returns:
- a stream of random generators.
-