Class: RandomDataGenerator

RandomDataGenerator


new RandomDataGenerator()

An instance of RandomDataGenerator is exported as engine/rnd.

Source:

Methods


between(min, max)

Returns a random integer between and including min and max.
This method is an alias for RandomDataGenerator.integerInRange.

Parameters:
Name Type Description
min number

The minimum value in the range.

max number

The maximum value in the range.

Source:
Returns:

A random number between min and max.

Type
number

frac()

Returns a random real number between 0 and 1.

Source:
Returns:

A random real number between 0 and 1.

Type
number

integer()

Returns a random integer between 0 and 2^32.

Source:
Returns:

A random integer between 0 and 2^32.

Type
number

integerInRange(min, max)

Returns a random integer between and including min and max.

Parameters:
Name Type Description
min number

The minimum value in the range.

max number

The maximum value in the range.

Source:
Returns:

A random number between min and max.

Type
number

normal()

Returns a random real number between -1 and 1.

Source:
Returns:

A random real number between -1 and 1.

Type
number

pick(ary)

Returns a random member of array.

Parameters:
Name Type Description
ary Array

An Array to pick a random member of.

Source:
Returns:

A random member of the array.

Type
any

real()

Returns a random real number between 0 and 2^32.

Source:
Returns:

A random real number between 0 and 2^32.

Type
number

realInRange(min, max)

Returns a random real number between min and max.

Parameters:
Name Type Description
min number

The minimum value in the range.

max number

The maximum value in the range.

Source:
Returns:

A random number between min and max.

Type
number

sow(seeds)

Reset the seed of the random data generator.

Note: the seed array is only processed up to the first undefined (or null) value, should such be present.

Parameters:
Name Type Description
seeds Array.<any>

The array of seeds: the toString() of each value is used.

Source:

state( [state])

Gets or Sets the state of the generator. This allows you to retain the values
that the generator is using between games, i.e. in a game save file.

To seed this generator with a previously saved state you can pass it as the
seed value in your game config, or call this method directly after Phaser has booted.

Call this method with no parameters to return the current state.

If providing a state it should match the same format that this method
returns, which is a string with a header !rnd followed by the c,
s0, s1 and s2 values respectively, each comma-delimited.

Parameters:
Name Type Argument Description
state string <optional>

Generator state to be set.

Source:
Returns:

The current state of the generator.

Type
string

uuid()

Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368

Source:
Returns:

A valid RFC4122 version4 ID hex string

Type
string

weightedPick(ary)

Returns a random member of array, favoring the earlier entries.

Parameters:
Name Type Description
ary Array

An Array to pick a random member of.

Source:
Returns:

A random member of the array.

Type
any

Class: RandomDataGenerator

RandomDataGenerator


new RandomDataGenerator( [seeds])

Parameters:
Name Type Argument Default Description
seeds Array | String <optional>
[]

An array of values to use as the seed, or a generator state (from {#state}).

Source:

Methods


between(min, max)

Returns a random integer between and including min and max.
This method is an alias for RandomDataGenerator.integerInRange.

Parameters:
Name Type Description
min number

The minimum value in the range.

max number

The maximum value in the range.

Source:
Returns:

A random number between min and max.

Type
number

frac()

Returns a random real number between 0 and 1.

Source:
Returns:

A random real number between 0 and 1.

Type
number

integer()

Returns a random integer between 0 and 2^32.

Source:
Returns:

A random integer between 0 and 2^32.

Type
number

integerInRange(min, max)

Returns a random integer between and including min and max.

Parameters:
Name Type Description
min number

The minimum value in the range.

max number

The maximum value in the range.

Source:
Returns:

A random number between min and max.

Type
number

normal()

Returns a random real number between -1 and 1.

Source:
Returns:

A random real number between -1 and 1.

Type
number

pick(ary)

Returns a random member of array.

Parameters:
Name Type Description
ary Array

An Array to pick a random member of.

Source:
Returns:

A random member of the array.

Type
any

real()

Returns a random real number between 0 and 2^32.

Source:
Returns:

A random real number between 0 and 2^32.

Type
number

realInRange(min, max)

Returns a random real number between min and max.

Parameters:
Name Type Description
min number

The minimum value in the range.

max number

The maximum value in the range.

Source:
Returns:

A random number between min and max.

Type
number

sow(seeds)

Reset the seed of the random data generator.

Note: the seed array is only processed up to the first undefined (or null) value, should such be present.

Parameters:
Name Type Description
seeds Array.<any>

The array of seeds: the toString() of each value is used.

Source:

state( [state])

Gets or Sets the state of the generator. This allows you to retain the values
that the generator is using between games, i.e. in a game save file.

To seed this generator with a previously saved state you can pass it as the
seed value in your game config, or call this method directly after Phaser has booted.

Call this method with no parameters to return the current state.

If providing a state it should match the same format that this method
returns, which is a string with a header !rnd followed by the c,
s0, s1 and s2 values respectively, each comma-delimited.

Parameters:
Name Type Argument Description
state string <optional>

Generator state to be set.

Source:
Returns:

The current state of the generator.

Type
string

uuid()

Returns a valid RFC4122 version4 ID hex string from https://gist.github.com/1308368

Source:
Returns:

A valid RFC4122 version4 ID hex string

Type
string

weightedPick(ary)

Returns a random member of array, favoring the earlier entries.

Parameters:
Name Type Description
ary Array

An Array to pick a random member of.

Source:
Returns:

A random member of the array.

Type
any