Top Description Fields Constructors Methods
org.apache.commons.math3.random

public abstract Class BitsStreamGenerator

extends Object
implements RandomGenerator, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.math3.random.RandomGenerator
Known Direct Subclasses
org.apache.commons.math3.random.ISAACRandom, org.apache.commons.math3.random.MersenneTwister, org.apache.commons.math3.random.AbstractWell
Imports
java.io.Serializable, org.apache.commons.math3.exception.NotStrictlyPositiveException, .OutOfRangeException, org.apache.commons.math3.util.FastMath

Base class for random number generators that generates bits streams.
Since
2.0

Field Summary

Modifier and TypeField and Description
private double
nextGaussian

Next gaussian.

private static final long
serialVersionUID

Serializable version identifier

Constructor Summary

AccessConstructor and Description
public
BitsStreamGenerator()

Creates a new random number generator.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Clears the cache used by the default implementation of nextGaussian.

protected abstract int

Returns:

random bits generated
next
(int
number of random bits to produce
bits
)

Generate next pseudorandom number.

public boolean
nextBoolean()

Implements org.apache.commons.math3.random.RandomGenerator.nextBoolean.

Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.

public void
nextBytes(byte[]
Array in which to put the generated bytes. Cannot be null.
bytes
)

Implements org.apache.commons.math3.random.RandomGenerator.nextBytes.

Generates random bytes and places them into a user-supplied array.

public void
nextBytes(byte[]
Array in which to put the generated bytes. Cannot be null.
bytes
,
int
Index at which to start inserting the generated bytes.
start
,
int
Number of bytes to insert.
len
)

Generates random bytes and places them into a user-supplied array.

private void
nextBytesFill(byte[]
Array in which to put the generated bytes. Cannot be null.
bytes
,
int
Index at which to start inserting the generated bytes.
start
,
int
Number of bytes to insert.
len
)

Generates random bytes and places them into a user-supplied array.

public double
nextDouble()

Implements org.apache.commons.math3.random.RandomGenerator.nextDouble.

Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

public float
nextFloat()

Implements org.apache.commons.math3.random.RandomGenerator.nextFloat.

Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

public double
nextGaussian()

Implements org.apache.commons.math3.random.RandomGenerator.nextGaussian.

Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

public int
nextInt()

Implements org.apache.commons.math3.random.RandomGenerator.nextInt.

Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.

public int
nextInt(int
the bound on the random number to be returned. Must be positive.
n
)

Implements org.apache.commons.math3.random.RandomGenerator.nextInt.

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

public long
nextLong()

Implements org.apache.commons.math3.random.RandomGenerator.nextLong.

Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.

public long

Returns:

a pseudorandom, uniformly distributed long value between 0 (inclusive) and n (exclusive).
nextLong
(long
the bound on the random number to be returned. Must be positive.
n
)

Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

public abstract void
setSeed(int
the seed value
seed
)

Redeclares org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using an int seed.

public abstract void
setSeed(int[]
the seed value
seed
)

Redeclares org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using an int array seed.

public abstract void
setSeed(long
the seed value
seed
)

Redeclares org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using a long seed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nextGaussianback to summary
private double nextGaussian

Next gaussian.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version identifier

Constructor Detail

BitsStreamGeneratorback to summary
public BitsStreamGenerator()

Creates a new random number generator.

Method Detail

clearback to summary
public void clear()

Clears the cache used by the default implementation of nextGaussian.

nextback to summary
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) and nextLong().

Parameters
bits:int

number of random bits to produce

Returns:int

random bits generated

nextBooleanback to summary
public boolean nextBoolean()

Implements org.apache.commons.math3.random.RandomGenerator.nextBoolean.

Doc from org.apache.commons.math3.random.RandomGenerator.nextBoolean.

Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.

Returns:boolean

the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence

nextBytesback to summary
public void nextBytes(byte[] bytes)

Implements org.apache.commons.math3.random.RandomGenerator.nextBytes.

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:byte[]

Array in which to put the generated bytes. Cannot be null.

nextBytesback to summary
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:byte[]

Array in which to put the generated bytes. Cannot be null.

start:int

Index at which to start inserting the generated bytes.

len:int

Number of bytes to insert.

Exceptions
OutOfRangeException:
  • if start < 0 or start >= bytes.length.
  • if len < 0 or len > bytes.length - start.
nextBytesFillback to summary
private void nextBytesFill(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:byte[]

Array in which to put the generated bytes. Cannot be null.

start:int

Index at which to start inserting the generated bytes.

len:int

Number of bytes to insert.

nextDoubleback to summary
public double nextDouble()

Implements org.apache.commons.math3.random.RandomGenerator.nextDouble.

Doc from org.apache.commons.math3.random.RandomGenerator.nextDouble.

Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

Returns:double

the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence

nextFloatback to summary
public float nextFloat()

Implements org.apache.commons.math3.random.RandomGenerator.nextFloat.

Doc from org.apache.commons.math3.random.RandomGenerator.nextFloat.

Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

Returns:float

the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence

nextGaussianback to summary
public double nextGaussian()

Implements org.apache.commons.math3.random.RandomGenerator.nextGaussian.

Doc from org.apache.commons.math3.random.RandomGenerator.nextGaussian.

Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

Returns:double

the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence

nextIntback to summary
public int nextInt()

Implements org.apache.commons.math3.random.RandomGenerator.nextInt.

Doc from org.apache.commons.math3.random.RandomGenerator.nextInt.

Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence. All 232 possible int values should be produced with (approximately) equal probability.

Returns:int

the next pseudorandom, uniformly distributed int value from this random number generator's sequence

nextIntback to summary
public int nextInt(int n) throws IllegalArgumentException

Implements org.apache.commons.math3.random.RandomGenerator.nextInt.

Doc from org.apache.commons.math3.random.RandomGenerator.nextInt.

Returns a pseudorandom, uniformly distributed int value 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) % n with next(31) values rejected (i.e. regenerated) until a value that is larger than the remainder of Integer.MAX_VALUE / n is generated. Rejection of this initial segment is necessary to ensure a uniform distribution.

Parameters
n:int

the bound on the random number to be returned. Must be positive.

Returns:int

a pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive).

Exceptions
IllegalArgumentException:
if n is not positive.
nextLongback to summary
public long nextLong()

Implements org.apache.commons.math3.random.RandomGenerator.nextLong.

Doc from org.apache.commons.math3.random.RandomGenerator.nextLong.

Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence. All 264 possible long values should be produced with (approximately) equal probability.

Returns:long

the next pseudorandom, uniformly distributed long value from this random number generator's sequence

nextLongback to summary
public long nextLong(long n) throws IllegalArgumentException

Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

Parameters
n:long

the bound on the random number to be returned. Must be positive.

Returns:long

a pseudorandom, uniformly distributed long value between 0 (inclusive) and n (exclusive).

Exceptions
IllegalArgumentException:
if n is not positive.
setSeedback to summary
public abstract void setSeed(int seed)

Redeclares org.apache.commons.math3.random.RandomGenerator.setSeed.

Doc from org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using an int seed.

Sequences of values generated starting with the same seeds should be identical.

Parameters
seed:int

the seed value

setSeedback to summary
public abstract void setSeed(int[] seed)

Redeclares org.apache.commons.math3.random.RandomGenerator.setSeed.

Doc from org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using an int array seed.

Sequences of values generated starting with the same seeds should be identical.

Parameters
seed:int[]

the seed value

setSeedback to summary
public abstract void setSeed(long seed)

Redeclares org.apache.commons.math3.random.RandomGenerator.setSeed.

Doc from org.apache.commons.math3.random.RandomGenerator.setSeed.

Sets the seed of the underlying random number generator using a long seed.

Sequences of values generated starting with the same seeds should be identical.

Parameters
seed:long

the seed value