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

public Class ISAACRandom

extends BitsStreamGenerator
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, org.apache.commons.math3.util.FastMath

ISAAC: 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
3.0

Field Summary

Modifier and TypeField and Description
private final int[]
arr

Service variable.

private int
count

Count through the results in rsl[]

private static final int
GLD_RATIO

The golden ratio

private static final int
H_SIZE

Half-size of rsl[] and mem[]

private int
isaacA

Accumulator

private int
isaacB

The last result

private int
isaacC

Counter, guarantees cycle is at least 2^40

private int
isaacI

Service variable.

private int
isaacJ

Service variable.

private int
isaacX

Service variable.

private static final int
MASK

For pseudo-random lookup

private final int[]
mem

The internal state

private final int[]
rsl

The results given to the user

private static final long
private static final int
SIZE

Size of rsl[] and mem[]

private static final int
SIZE_L

Log of size of rsl[] and mem[]

Constructor Summary

AccessConstructor and Description
public
ISAACRandom()

Creates a new ISAAC random number generator.

public
ISAACRandom(long
Initial seed.
seed
)

Creates a new ISAAC random number generator using a single long seed.

public
ISAACRandom(int[]
Initial seed. If null, the seed will be related to the current time.
seed
)

Creates a new ISAAC random number generator using an int array seed.

Method Summary

Modifier and TypeMethod and Description
private void
initState()

Initialize, or reinitialize, this instance of rand.

private void
isaac()

Generate 256 results

private void
isaac2()

Intermediate internal loop.

private void
isaac3()

Lowest level internal loop.

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

Implements abstract org.apache.commons.math3.random.BitsStreamGenerator.next.

Generate next pseudorandom number.

public void
setSeed(int
the seed value
seed
)

Implements abstract org.apache.commons.math3.random.BitsStreamGenerator.setSeed.

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

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

public void
setSeed(long
the seed value
seed
)

Implements abstract org.apache.commons.math3.random.BitsStreamGenerator.setSeed.

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

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

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

Implements abstract org.apache.commons.math3.random.BitsStreamGenerator.setSeed.

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

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

private void
setState(int
First index into mem array.
start
)

Set the state by copying the internal arrays.

private void
shuffle()

Shuffle array.

Inherited from org.apache.commons.math3.random.BitsStreamGenerator:
clearnextBooleannextBytesnextBytesnextDoublenextFloatnextGaussiannextIntnextIntnextLongnextLong

Field Detail

arrback to summary
private final int[] arr

Service variable.

countback to summary
private int count

Count through the results in rsl[]

GLD_RATIOback to summary
private static final int GLD_RATIO

The golden ratio

H_SIZEback to summary
private static final int H_SIZE

Half-size of rsl[] and mem[]

isaacAback to summary
private int isaacA

Accumulator

isaacBback to summary
private int isaacB

The last result

isaacCback to summary
private int isaacC

Counter, guarantees cycle is at least 2^40

isaacIback to summary
private int isaacI

Service variable.

isaacJback to summary
private int isaacJ

Service variable.

isaacXback to summary
private int isaacX

Service variable.

MASKback to summary
private static final int MASK

For pseudo-random lookup

memback to summary
private final int[] mem

The internal state

rslback to summary
private final int[] rsl

The results given to the user

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.math3.random.BitsStreamGenerator.serialVersionUID.

Serializable version identifier

SIZEback to summary
private static final int SIZE

Size of rsl[] and mem[]

SIZE_Lback to summary
private static final int SIZE_L

Log of size of rsl[] and mem[]

Constructor Detail

ISAACRandomback to summary
public ISAACRandom()

Creates a new ISAAC random number generator.
The instance is initialized using a combination of the current time and system hash code of the instance as the seed.

ISAACRandomback to summary
public ISAACRandom(long seed)

Creates a new ISAAC random number generator using a single long seed.

Parameters
seed:long

Initial seed.

ISAACRandomback to summary
public ISAACRandom(int[] seed)

Creates a new ISAAC random number generator using an int array seed.

Parameters
seed:int[]

Initial seed. If null, the seed will be related to the current time.

Method Detail

initStateback to summary
private void initState()

Initialize, or reinitialize, this instance of rand.

isaacback to summary
private void isaac()

Generate 256 results

isaac2back to summary
private void isaac2()

Intermediate internal loop.

isaac3back to summary
private void isaac3()

Lowest level internal loop.

nextback to summary
protected int next(int bits)

Implements abstract org.apache.commons.math3.random.BitsStreamGenerator.next.

Doc from org.apache.commons.math3.random.BitsStreamGenerator.next.

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

Annotations
@Override
setSeedback to summary
public void setSeed(int seed)

Implements abstract org.apache.commons.math3.random.BitsStreamGenerator.setSeed.

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

Doc from org.apache.commons.math3.random.BitsStreamGenerator.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

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

the seed value

Annotations
@Override
setSeedback to summary
public void setSeed(long seed)

Implements abstract org.apache.commons.math3.random.BitsStreamGenerator.setSeed.

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

Doc from org.apache.commons.math3.random.BitsStreamGenerator.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

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

the seed value

Annotations
@Override
setSeedback to summary
public void setSeed(int[] seed)

Implements abstract org.apache.commons.math3.random.BitsStreamGenerator.setSeed.

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

Doc from org.apache.commons.math3.random.BitsStreamGenerator.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[]

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

the seed value

Annotations
@Override
setStateback to summary
private void setState(int start)

Set the state by copying the internal arrays.

Parameters
start:int

First index into mem array.

shuffleback to summary
private void shuffle()

Shuffle array.