Class BitsStreamGenerator
- All Implemented Interfaces:
Serializable,RandomGenerator
- Direct Known Subclasses:
AbstractWell,ISAACRandom,MersenneTwister
- Since:
- 2.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the cache used by the default implementation ofnextGaussian.protected abstract intnext(int bits) Generate next pseudorandom number.booleanReturns the next pseudorandom, uniformly distributedbooleanvalue from this random number generator's sequence.voidnextBytes(byte[] bytes) Generates random bytes and places them into a user-supplied array.voidnextBytes(byte[] bytes, int start, int len) Generates random bytes and places them into a user-supplied array.doubleReturns the next pseudorandom, uniformly distributeddoublevalue between0.0and1.0from this random number generator's sequence.floatReturns the next pseudorandom, uniformly distributedfloatvalue between0.0and1.0from this random number generator's sequence.doubleReturns the next pseudorandom, Gaussian ("normally") distributeddoublevalue with mean0.0and standard deviation1.0from this random number generator's sequence.intnextInt()Returns the next pseudorandom, uniformly distributedintvalue from this random number generator's sequence.intnextInt(int n) Returns a pseudorandom, uniformly distributedintvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.longnextLong()Returns the next pseudorandom, uniformly distributedlongvalue from this random number generator's sequence.longnextLong(long n) Returns a pseudorandom, uniformly distributedlongvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.abstract voidsetSeed(int seed) Sets the seed of the underlying random number generator using anintseed.abstract voidsetSeed(int[] seed) Sets the seed of the underlying random number generator using anintarray seed.abstract voidsetSeed(long seed) Sets the seed of the underlying random number generator using alongseed.
-
Constructor Details
-
BitsStreamGenerator
public BitsStreamGenerator()Creates a new random number generator.
-
-
Method Details
-
setSeed
public abstract void setSeed(int seed) Sets the seed of the underlying random number generator using anintseed.Sequences of values generated starting with the same seeds should be identical.
- Specified by:
setSeedin interfaceRandomGenerator- Parameters:
seed- the seed value
-
setSeed
public abstract void setSeed(int[] seed) Sets the seed of the underlying random number generator using anintarray seed.Sequences of values generated starting with the same seeds should be identical.
- Specified by:
setSeedin interfaceRandomGenerator- Parameters:
seed- the seed value
-
setSeed
public abstract void setSeed(long seed) Sets the seed of the underlying random number generator using alongseed.Sequences of values generated starting with the same seeds should be identical.
- Specified by:
setSeedin interfaceRandomGenerator- Parameters:
seed- the seed value
-
next
protected abstract int next(int bits) Generate next pseudorandom number.This method is the core generation algorithm. It is used by all the public generation methods for the various primitive types
nextBoolean(),nextBytes(byte[]),nextDouble(),nextFloat(),nextGaussian(),nextInt(),next(int)andnextLong().- Parameters:
bits- number of random bits to produce- Returns:
- random bits generated
-
nextBoolean
public boolean nextBoolean()Returns the next pseudorandom, uniformly distributedbooleanvalue from this random number generator's sequence.- Specified by:
nextBooleanin interfaceRandomGenerator- Returns:
- the next pseudorandom, uniformly distributed
booleanvalue from this random number generator's sequence
-
nextDouble
public double nextDouble()Returns the next pseudorandom, uniformly distributeddoublevalue between0.0and1.0from this random number generator's sequence.- Specified by:
nextDoublein interfaceRandomGenerator- Returns:
- the next pseudorandom, uniformly distributed
doublevalue between0.0and1.0from this random number generator's sequence
-
nextFloat
public float nextFloat()Returns the next pseudorandom, uniformly distributedfloatvalue between0.0and1.0from this random number generator's sequence.- Specified by:
nextFloatin interfaceRandomGenerator- Returns:
- the next pseudorandom, uniformly distributed
floatvalue between0.0and1.0from this random number generator's sequence
-
nextGaussian
public double nextGaussian()Returns the next pseudorandom, Gaussian ("normally") distributeddoublevalue with mean0.0and standard deviation1.0from this random number generator's sequence.- Specified by:
nextGaussianin interfaceRandomGenerator- Returns:
- the next pseudorandom, Gaussian ("normally") distributed
doublevalue with mean0.0and standard deviation1.0from this random number generator's sequence
-
nextInt
public int nextInt()Returns the next pseudorandom, uniformly distributedintvalue from this random number generator's sequence. All 232 possibleintvalues should be produced with (approximately) equal probability.- Specified by:
nextIntin interfaceRandomGenerator- Returns:
- the next pseudorandom, uniformly distributed
intvalue from this random number generator's sequence
-
nextInt
Returns a pseudorandom, uniformly distributedintvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.This default implementation is copied from Apache Harmony java.util.Random (r929253).
Implementation notes:
- If n is a power of 2, this method returns
(int) ((n * (long) next(31)) >> 31). - If n is not a power of 2, what is returned is
next(31) % nwithnext(31)values rejected (i.e. regenerated) until a value that is larger than the remainder ofInteger.MAX_VALUE / nis generated. Rejection of this initial segment is necessary to ensure a uniform distribution.
- Specified by:
nextIntin interfaceRandomGenerator- Parameters:
n- the bound on the random number to be returned. Must be positive.- Returns:
- a pseudorandom, uniformly distributed
intvalue between 0 (inclusive) and n (exclusive). - Throws:
IllegalArgumentException- if n is not positive.
- If n is a power of 2, this method returns
-
nextLong
public long nextLong()Returns the next pseudorandom, uniformly distributedlongvalue from this random number generator's sequence. All 264 possiblelongvalues should be produced with (approximately) equal probability.- Specified by:
nextLongin interfaceRandomGenerator- Returns:
- the next pseudorandom, uniformly distributed
longvalue from this random number generator's sequence
-
nextLong
Returns a pseudorandom, uniformly distributedlongvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.- Parameters:
n- the bound on the random number to be returned. Must be positive.- Returns:
- a pseudorandom, uniformly distributed
longvalue between 0 (inclusive) and n (exclusive). - Throws:
IllegalArgumentException- if n is not positive.
-
clear
public void clear()Clears the cache used by the default implementation ofnextGaussian. -
nextBytes
public void nextBytes(byte[] bytes) Generates random bytes 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 interfaceRandomGenerator- Parameters:
bytes- Array in which to put the generated bytes. Cannot benull.
-
nextBytes
public void nextBytes(byte[] bytes, int start, int len) Generates random bytes 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.
- 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.- Throws:
OutOfRangeException- ifstart < 0orstart >= bytes.length.OutOfRangeException- iflen < 0orlen > bytes.length - start.
-