Skip to main content

RandomGenerator

Description:

  A random number generation object which has its own random state.

type

Type: Function.

Description:

  Gets the type of the object as a string.

Signature:

type: function(self: RandomGenerator): string

Returns:

Return TypeDescription
stringThe type as a string.

Of

Type: Function.

Description:

  Checks whether an object is of a certain type. If the object has the type with the specified name in its hierarchy, this function will return true.

Signature:

typeOf: function(self: RandomGenerator, type_name: string): boolean

Parameters:

ParameterTypeDescription
type_namestringThe name of the type to check for.

Returns:

Return TypeDescription
booleanTrue if the object is of the specified type, false otherwise.

release

Type: Function.

Description:

  Destroys the object's Lua reference. The object will be completely deleted if it's not referenced by any other LÖVE object or thread. This method can be used to immediately clean up resources without waiting for Lua's garbage collector.

Signature:

release: function(self: RandomGenerator): boolean

Returns:

Return TypeDescription
booleanTrue if the object was released by this call, false if it had been previously released.

random

Type: Function.

Description:

  Generates a pseudo-random number in a platform independent manner.

Signature:

random: function(self: RandomGenerator): number

Returns:

Return TypeDescription
numbernumber — The pseudo-random number.

random

Type: Function.

Description:

  Generates a pseudo-random number in a platform independent manner.

Signature:

random: function(self: RandomGenerator, upper: number): number

Parameters:

ParameterTypeDescription
uppernumberThe maximum possible value it should return.

Returns:

Return TypeDescription
numberThe pseudo-random integer number.

random

Type: Function.

Description:

  Generates a pseudo-random number in a platform independent manner.

Signature:

random: function(self: RandomGenerator, lower: number, upper: number): number

Parameters:

ParameterTypeDescription
lowernumberThe minimum possible value it should return.
uppernumberThe maximum possible value it should return.

Returns:

Return TypeDescription
numberThe pseudo-random integer number.

randomNormal

Type: Function.

Description:

  Get a normally distributed pseudo random number.

Signature:

randomNormal: function(self: RandomGenerator, standard_deviation?: number, mean?: number): number

Parameters:

ParameterTypeDescription
standard_deviationnumberStandard deviation of the distribution. (Default: 1.)
meannumberThe mean of the distribution. (Default: 0.)

Returns:

Return TypeDescription
numberNormally distributed random number with variance (stddev)² and the specified mean.

setSeed

Type: Function.

Description:

  Sets the seed of the random number generator using the specified integer number.

Signature:

setSeed: function(self: RandomGenerator, seed: number)

Parameters:

ParameterTypeDescription
seednumberThe integer number with which you want to seed the randomization. Must be within the range of 2^53.

setSeed

Type: Function.

Description:

  Sets the seed of the random number generator using the specified integer number.

Signature:

setSeed: function(self: RandomGenerator, low: number, high: number)

Parameters:

ParameterTypeDescription
lownumberThe lower 32 bits of the seed value. Must be within the range of 2^32 - 1.
highnumberThe higher 32 bits of the seed value. Must be within the range of 2^32 - 1.

getSeed

Type: Function.

Description:

  Gets the seed of the random number generator object. The seed is split into two numbers due to Lua's use of doubles for all number values - doubles can't accurately represent integer values above 2^53, but the seed value is an integer number in the range of 2^64 - 1.

Signature:

getSeed: function(self: RandomGenerator): number, number

Returns:

Return TypeDescription
numberInteger number representing the lower 32 bits of the RandomGenerator's 64 bit seed value.
numberInteger number representing the higher 32 bits of the RandomGenerator's 64 bit seed value.

setState

Type: Function.

Description:

  Sets the current state of the random number generator. The value used as an argument for this function is an opaque string and should only originate from a previous call to RandomGenerator:getState in the same major version of LÖVE. This is different from RandomGenerator:setSeed in that setState directly sets the RandomGenerator's current implementation-dependent state, whereas setSeed gives it a new seed value. Overload details:

  1. The effect of the state string does not depend on the current operating system.

Signature:

setState: function(self: RandomGenerator, state: string)

Parameters:

ParameterTypeDescription
statestringThe new state of the RandomGenerator object, represented as a string. This should originate from a previous call to RandomGenerator:getState.

getState

Type: Function.

Description:

  Gets the current state of the random number generator. This returns an opaque string which is only useful for later use with RandomGenerator:setState in the same major version of LÖVE. This is different from RandomGenerator:getSeed in that getState gets the RandomGenerator's current state, whereas getSeed gets the previously set seed number. Overload details:

  1. The value of the state string does not depend on the current operating system.

Signature:

getState: function(self: RandomGenerator): string

Returns:

Return TypeDescription
stringThe current state of the RandomGenerator object, represented as a string.