Class: PRNG

system.numeric. PRNG


new PRNG( [value])

A pseudo random number generator (PRNG) is an algorithm for generating a sequence of numbers that approximates the properties of random numbers.

A pseudo random number generator (PRNG) is an algorithm for generating a sequence of numbers that approximates the properties of random numbers.

Implementation of the Park Miller (1988) "minimal standard" linear congruential pseudo-random number generator. For a full explanation visit: http://www.firstpr.com.au/dsp/rand31/

The generator uses a modulus constant ((m) of 2^31 - 1) which is a Mersenne Prime number and a full-period-multiplier of 16807. Output is a 31 bit unsigned integer. The range of values output is 1 to 2147483646 (2^31-1) and the seed must be in this range too.

Parameters:
Name Type Argument Default Description
value number <optional>
0

The optional default value of the PRNG object, if the passed-in value is >=1 a random value is generated with the Math.random() static method.

Members


value :number

Defines the current random value with a 31 bit unsigned integer between 1 and 0X7FFFFFFE inclusive (don't use 0).

Type:
  • number

Methods


randomInt()

Provides the next pseudo random number as an unsigned integer (31 bits).

Returns:

The next pseudo random number as an unsigned integer (31 bits).


randomIntByMinMax( [min] [, max])

Provides the next pseudo random number as an unsigned integer (31 bits) between a minimum value and maximum value.

Parameters:
Name Type Argument Default Description
min number <optional>
0

The minimum range value to evaluates the pseudo random number.

max number <optional>
1

The maximum range value to evaluates the pseudo random number.

Returns:

The next pseudo random number as an unsigned integer (31 bits) between a minimum value and maximum value.


randomIntByRange(range)

Provides the next pseudo random number as an unsigned integer (31 bits) between a given range.

Parameters:
Name Type Description
range system.numeric.Range

The range object to evaluate the pseudo random number.

Returns:

The next pseudo random number as an unsigned integer (31 bits) between a minimum value and maximum value.


randomNumber()

Provides the next pseudo random number as a float between nearly 0 and nearly 1.0.

Returns:

The next pseudo random number as a float between nearly 0 and nearly 1.0.


randomNumberByMinMax( [min] [, max])

Provides the next pseudo random number as a float between a minimum value and maximum value.

Parameters:
Name Type Argument Default Description
min number <optional>
0

The minimum range value to evaluates the pseudo random number.

max number <optional>
1

The maximum range value to evaluates the pseudo random number.

Returns:

The next pseudo random number as a float between a minimum value and maximum value.


randomNumberByRange(range)

Provides the next pseudo random number as a float between a given range.

Parameters:
Name Type Description
range system.numeric.Range

The range to born the number.

Returns:

The next pseudo random number as a float in a specific range.


toString()

Returns the string representation of this instance.

Returns:

the string representation of this instance.


valueOf()

Returns the string representation of this instance.

Returns:

the string representation of this instance.