shadow:utility

Class Random

Parent class

shadow:standard@Object

Interfaces

shadow:standard@CanEqual<shadow:utility@Random>

class Random

Class Random allows the generation of pseudorandom numbers using the Mersenne Twister algorithm. This implementation is based on Sean Luke's Java implementation of version MT199937(99/10/29) of the Mersenne Twister algorithm with the initialization improved using the new 2002/1/26 initialization algorithm.

See Also

Create Summary

Modifiers Return Types Method and Description
public () create()

Creates a Random object using the nanoseconds since the Unix Epoch as a seed.

public () create(long seed)

Creates a Random object using the given value as a seed.

public () create(uint[] array)

Creates a Random object using an array of values as a seed.

Destroy Summary

Modifiers Return Types Method and Description
public () destroy()

Method Summary

Modifiers Return Types Method and Description
public readonly (Random) copy(AddressMap addresses)
public readonly (boolean) equal(Random other)

Checks if the current Random object has the same state as another Random object.

protected (int) next(int bits)

Produces an integer with the given number of bits filled with pseudorandom values.

public (boolean) nextBoolean()

Produces a pseudorandom boolean value with even chances of true and false.

public (boolean) nextBoolean(double probability)

Produces a pseudorandom boolean value with the specified probability of it being true.

public (byte) nextByte()

Produces a pseudorandom byte uniformly distributed across all possible byte values.

public () nextBytes(byte[] bytes)

Fills an array of byte values with pseudorandom numbers.

public (double) nextDouble()

Produces a pseudorandom double value uniformly distributed between 0.0 (inclusive) and 1.0 (exclusive).

public (double) nextDouble(boolean includeZero, boolean includeOne)

Produces a pseudorandom double value uniformly distributed between 0.0 and 1.0 where the parameters determine if 0.0 and 1.0 are included in the range or not.

public (float) nextFloat()

Produces a pseudorandom float value uniformly distributed between 0.0 (inclusive) and 1.0 (exclusive).

public (float) nextFloat(boolean includeZero, boolean includeOne)

Produces a pseudorandom float value uniformly distributed between 0.0 and 1.0 where the parameters determine if 0.0 and 1.0 are included in the range or not.

public (double) nextGaussian()

Produces a pseudorandom double value with a Gaussian distribution whose mean is 0.0 and standard deviation is 1.0.

public (int) nextInt()

Produces a pseudorandom int uniformly distributed across all possible int values.

public (int) nextInt(int n)

Produces a pseudorandom int value between 0 (inclusive) and the specified value (exclusive).

public (long) nextLong()

Produces a pseudorandom long uniformly distributed across all possible long values.

public (long) nextLong(long n)

Produces a pseudorandom long value between 0 (inclusive) and the specified value (exclusive).

public (short) nextShort()

Produces a pseudorandom short uniformly distributed across all possible short values.

public (ubyte) nextUByte()

Produces a pseudorandom ubyte uniformly distributed across all possible ubyte values.

public (uint) nextUInt()

Produces a pseudorandom uint uniformly distributed across all possible uint values.

public (ulong) nextULong()
public (ushort) nextUShort()

Produces a pseudorandom ushort uniformly distributed across all possible ushort values.

Property Summary

Modifiers Return Types Method and Description
public set () seed(long seed)

Initalizes the pseudorandom number generator with the given seed value.

public set () seed(uint[] array)

Initalizes the pseudorandom number generator with the given array of values.

Create Detail

create

public create() => ()

Creates a Random object using the nanoseconds since the Unix Epoch as a seed.

create

public create(long seed) => ()

Creates a Random object using the given value as a seed.

Parameters

seed - seed for pseudorandom number generation

create

public create(uint[] array) => ()

Creates a Random object using an array of values as a seed.

Parameters

array - seed for pseudorandom number generation

Destroy Detail

destroy

public destroy() => ()

Method Detail

copy

public readonly copy(AddressMap addresses) => (Random)

equal

public readonly equal(Random other) => (boolean)

Checks if the current Random object has the same state as another Random object.

Parameters

other - object to compare to

Returns

true if the two objects have the same state

next

protected next(int bits) => (int)

Produces an integer with the given number of bits filled with pseudorandom values.

Parameters

bits - number of random bits to generate

Returns

pseudorandom int value

nextBoolean

public nextBoolean() => (boolean)

Produces a pseudorandom boolean value with even chances of true and false.

Returns

pseudorandom boolean value

nextBoolean

public nextBoolean(double probability) => (boolean)

Produces a pseudorandom boolean value with the specified probability of it being true.

Parameters

probability - chance that the random value is true

Returns

pseudorandom boolean value

nextByte

public nextByte() => (byte)

Produces a pseudorandom byte uniformly distributed across all possible byte values.

Returns

pseudorandom byte value

nextBytes

public nextBytes(byte[] bytes) => ()

Fills an array of byte values with pseudorandom numbers.

Parameters

bytes - array to fill

nextDouble

public nextDouble() => (double)

Produces a pseudorandom double value uniformly distributed between 0.0 (inclusive) and 1.0 (exclusive).

Returns

pseudorandom double value

nextDouble

public nextDouble(boolean includeZero, boolean includeOne) => (double)

Produces a pseudorandom double value uniformly distributed between 0.0 and 1.0 where the parameters determine if 0.0 and 1.0 are included in the range or not.

Parameters

includeZero - if true, include 0.0 as a possible output

includeOne - if true, include 1.0 as a possible output

Returns

pseudorandom double value

nextFloat

public nextFloat() => (float)

Produces a pseudorandom float value uniformly distributed between 0.0 (inclusive) and 1.0 (exclusive).

Returns

pseudorandom float value

nextFloat

public nextFloat(boolean includeZero, boolean includeOne) => (float)

Produces a pseudorandom float value uniformly distributed between 0.0 and 1.0 where the parameters determine if 0.0 and 1.0 are included in the range or not.

Parameters

includeZero - if true, include 0.0 as a possible output

includeOne - if true, include 1.0 as a possible output

Returns

pseudorandom float value

nextGaussian

public nextGaussian() => (double)

Produces a pseudorandom double value with a Gaussian distribution whose mean is 0.0 and standard deviation is 1.0.

Returns

pseudorandom double value

nextInt

public nextInt() => (int)

Produces a pseudorandom int uniformly distributed across all possible int values.

Returns

pseudorandom int value

nextInt

public nextInt(int n) => (int)

Produces a pseudorandom int value between 0 (inclusive) and the specified value (exclusive).

Parameters

n - one more than the maximum random value

Returns

pseudorandom int value

nextLong

public nextLong() => (long)

Produces a pseudorandom long uniformly distributed across all possible long values.

Returns

pseudorandom long value

nextLong

public nextLong(long n) => (long)

Produces a pseudorandom long value between 0 (inclusive) and the specified value (exclusive).

Parameters

n - one more than the maximum random value

Returns

pseudorandom long value

nextShort

public nextShort() => (short)

Produces a pseudorandom short uniformly distributed across all possible short values.

Returns

pseudorandom short value

nextUByte

public nextUByte() => (ubyte)

Produces a pseudorandom ubyte uniformly distributed across all possible ubyte values.

Returns

pseudorandom ubyte value

nextUInt

public nextUInt() => (uint)

Produces a pseudorandom uint uniformly distributed across all possible uint values.

Returns

pseudorandom uint value

nextULong

public nextULong() => (ulong)

nextUShort

public nextUShort() => (ushort)

Produces a pseudorandom ushort uniformly distributed across all possible ushort values.

Returns

pseudorandom ushort value

Property Detail

seed

public set seed(long seed) => ()

Initalizes the pseudorandom number generator with the given seed value. The algorithm is only intended to use a 32-bit seed, so the two halves of the 64-bit seed value are XORed together to capture bits from both.

Parameters

seed - seed for pseudorandom number generation

seed

public set seed(uint[] array) => ()

Initalizes the pseudorandom number generator with the given array of values. The array must have a non-zero length. Only the first 624 values in the array are used. If the array has a shorter length, its values are used repeatedly in a wrap-around fashion.

Parameters

array - seed for pseudorandom number generation