Difference between revisions of "love.math.random"

m (Examples)
(Function)
Line 3: Line 3:
 
== Function ==
 
== Function ==
 
Get uniformly distributed pseudo-random real number within [0, 1].
 
Get uniformly distributed pseudo-random real number within [0, 1].
 +
 +
You might want to initialize the PRNG with [https://love2d.org/wiki/love.math.setRandomSeed setRandomSeed] before using this function.
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 11: Line 13:
 
=== Returns ===
 
=== Returns ===
 
{{param|number|number|The pseudo-random number.}}
 
{{param|number|number|The pseudo-random number.}}
 +
 
== Function ==
 
== Function ==
 
Get a uniformly distributed pseudo-random integer within [1, max].
 
Get a uniformly distributed pseudo-random integer within [1, max].

Revision as of 13:47, 4 October 2017

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

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

Function

Get uniformly distributed pseudo-random real number within [0, 1].

You might want to initialize the PRNG with setRandomSeed before using this function.

Synopsis

number = love.math.random( )

Arguments

None.

Returns

number number
The pseudo-random number.

Function

Get a uniformly distributed pseudo-random integer within [1, max].

Synopsis

number = love.math.random( max )

Arguments

number max
The maximum possible value it should return.

Returns

number number
The pseudo-random integer number.

Function

Get uniformly distributed pseudo-random integer within [min, max].

Synopsis

number = love.math.random( min, max )

Arguments

number min
The minimum possible value it should return.
number max
The maximum possible value it should return.

Returns

number number
The pseudo-random integer number.

Examples

Generates a number between 1 and 100 (both inclusive).

function love.load()
    randomNumber = love.math.random(1, 100)
end

See Also

Other Languages