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.
Modifiers | Return Types | Method and Description |
---|---|---|
public |
() |
create() Creates a |
public |
() |
create(long seed) Creates a |
public |
() |
create(uint[] array) Creates a |
Modifiers | Return Types | Method and Description |
---|---|---|
public |
() |
destroy() |
Modifiers | Return Types | Method and Description |
---|---|---|
public readonly |
(Random) |
copy(AddressMap addresses) |
public readonly |
(boolean) |
equal(Random other) Checks if the current |
protected |
(int) |
next(int bits) Produces an integer with the given number of bits filled with pseudorandom values. |
public |
(boolean) |
nextBoolean() Produces a pseudorandom |
public |
(boolean) |
nextBoolean(double probability) Produces a pseudorandom |
public |
(byte) |
nextByte() Produces a pseudorandom |
public |
() |
nextBytes(byte[] bytes) Fills an array of |
public |
(double) |
nextDouble() Produces a pseudorandom |
public |
(double) |
nextDouble(boolean includeZero, boolean includeOne) Produces a pseudorandom |
public |
(float) |
nextFloat() Produces a pseudorandom |
public |
(float) |
nextFloat(boolean includeZero, boolean includeOne) Produces a pseudorandom |
public |
(double) |
nextGaussian() Produces a pseudorandom |
public |
(int) |
nextInt() Produces a pseudorandom |
public |
(int) |
nextInt(int n) Produces a pseudorandom |
public |
(long) |
nextLong() Produces a pseudorandom |
public |
(long) |
nextLong(long n) Produces a pseudorandom |
public |
(short) |
nextShort() Produces a pseudorandom |
public |
(ubyte) |
nextUByte() Produces a pseudorandom |
public |
(uint) |
nextUInt() Produces a pseudorandom |
public |
(ulong) |
nextULong() |
public |
(ushort) |
nextUShort() Produces a pseudorandom |
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. |
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.
seed
- seed for pseudorandom number generation
public create(uint[] array) => ()
Creates a Random
object using an array of values as a seed.
array
- seed for pseudorandom number generation
public destroy() => ()
public readonly copy(AddressMap addresses) => (Random)
public readonly equal(Random other) => (boolean)
Checks if the current Random
object has the same state as another Random
object.
other
- object to compare to
true
if the two objects have the same state
protected next(int bits) => (int)
Produces an integer with the given number of bits filled with pseudorandom values.
bits
- number of random bits to generate
pseudorandom int
value
public nextBoolean() => (boolean)
Produces a pseudorandom boolean
value with even chances of true
and false
.
pseudorandom boolean
value
public nextBoolean(double probability) => (boolean)
Produces a pseudorandom boolean
value with the specified probability of it being true
.
probability
- chance that the random value is true
pseudorandom boolean
value
public nextByte() => (byte)
Produces a pseudorandom byte
uniformly distributed across all possible byte
values.
pseudorandom byte
value
public nextBytes(byte[] bytes) => ()
Fills an array of byte
values with pseudorandom numbers.
bytes
- array to fill
public nextDouble() => (double)
Produces a pseudorandom double
value uniformly distributed between 0.0 (inclusive) and 1.0 (exclusive).
pseudorandom double
value
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.
includeZero
- if true
, include 0.0 as a possible output
includeOne
- if true
, include 1.0 as a possible output
pseudorandom double
value
public nextFloat() => (float)
Produces a pseudorandom float
value uniformly distributed between 0.0 (inclusive) and 1.0 (exclusive).
pseudorandom float
value
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.
includeZero
- if true
, include 0.0 as a possible output
includeOne
- if true
, include 1.0 as a possible output
pseudorandom float
value
public nextGaussian() => (double)
Produces a pseudorandom double
value with a Gaussian distribution whose mean is 0.0 and standard deviation is 1.0.
pseudorandom double
value
public nextInt() => (int)
Produces a pseudorandom int
uniformly distributed across all possible int
values.
pseudorandom int
value
public nextInt(int n) => (int)
Produces a pseudorandom int
value between 0 (inclusive) and the specified value (exclusive).
n
- one more than the maximum random value
pseudorandom int
value
public nextLong() => (long)
Produces a pseudorandom long
uniformly distributed across all possible long
values.
pseudorandom long
value
public nextLong(long n) => (long)
Produces a pseudorandom long
value between 0 (inclusive) and the specified value (exclusive).
n
- one more than the maximum random value
pseudorandom long
value
public nextShort() => (short)
Produces a pseudorandom short
uniformly distributed across all possible short
values.
pseudorandom short
value
public nextUByte() => (ubyte)
Produces a pseudorandom ubyte
uniformly distributed across all possible ubyte
values.
pseudorandom ubyte
value
public nextUInt() => (uint)
Produces a pseudorandom uint
uniformly distributed across all possible uint
values.
pseudorandom uint
value
public nextULong() => (ulong)
public nextUShort() => (ushort)
Produces a pseudorandom ushort
uniformly distributed across all possible ushort
values.
pseudorandom ushort
value
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.
seed
- seed for pseudorandom number generation
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.
array
- seed for pseudorandom number generation