Difference between revisions of "love.math.random"

m
m (Added example)
Line 32: Line 32:
 
=== Returns ===
 
=== Returns ===
 
{{param|number|number|The pseudo random number.}}
 
{{param|number|number|The pseudo random number.}}
 +
 +
== Examples ==
 +
Generates a number between 1 and 100 inclusive, then prints it to the console window.
 +
<source lang="lua">
 +
function love.load()
 +
    randomNumber = love.math.random(1, 100)
 +
end
 +
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::love.math]]
 
* [[parent::love.math]]

Revision as of 02:23, 18 December 2013

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

Generates a pseudo random number in a platform independent way.

Function

Get uniformly distributed pseudo random number in [0,1].

Synopsis

number = love.math.random( )

Arguments

None.

Returns

number number
The pseudo random number.

Function

Get uniformly distributed pseudo random number in [0,max]

Synopsis

number = love.math.random( max )

Arguments

number max
The maximum possible value it should return.

Returns

number number
The pseudo random number.

Function

Get uniformly distributed pseudo random number in [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 number.

Examples

Generates a number between 1 and 100 inclusive, then prints it to the console window.

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

See Also

Other Languages