Class ISAACRandom
- java.lang.Object
-
- org.apache.commons.rng.core.BaseProvider
-
- org.apache.commons.rng.core.source32.IntProvider
-
- org.apache.commons.rng.core.source32.ISAACRandom
-
- All Implemented Interfaces:
RandomIntSource
,RestorableUniformRandomProvider
,UniformRandomProvider
public class ISAACRandom extends IntProvider
A fast cryptographic pseudo-random number generator.ISAAC (Indirection, Shift, Accumulate, Add, and Count) generates 32-bit random numbers. ISAAC has been designed to be cryptographically secure and is inspired by RC4. Cycles are guaranteed to be at least 240 values long, and they are 28295 values long on average. The results are uniformly distributed, unbiased, and unpredictable unless you know the seed.
This code is based (with minor changes and improvements) on the original implementation of the algorithm by Bob Jenkins.
- Since:
- 1.0
- See Also:
- ISAAC: a fast cryptographic pseudo-random number generator, ISAAC (Wikipedia)
-
-
Constructor Summary
Constructors Constructor Description ISAACRandom(int[] seed)
Creates a new ISAAC random number generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
getStateInternal()
Creates a snapshot of the RNG state.int
next()
protected void
setStateInternal(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, resetCachedState
-
Methods inherited from class org.apache.commons.rng.core.BaseProvider
checkIndex, checkStateSize, composeStateInternal, extendSeed, extendSeed, fillState, fillState, restoreState, saveState, splitStateInternal, toString
-
-
-
-
Constructor Detail
-
ISAACRandom
public ISAACRandom(int[] seed)
Creates a new ISAAC random number generator.- Parameters:
seed
- Initial seed
-
-
Method Detail
-
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)
-
next
public int next()
- Returns:
- the next random value.
-
-