Difference between revisions of "love.math.newRandomGenerator"

m (Added example)
Line 34: Line 34:
 
=== Returns ===
 
=== Returns ===
 
{{param|RandomGenerator|rng|A Random Number Generator object.}}
 
{{param|RandomGenerator|rng|A Random Number Generator object.}}
 
+
== Examples ==
 +
Creates a new RandomGenerator object, then generates a number between 1 and 100 inclusive.
 +
<source lang="lua">
 +
function love.load()
 +
rng = love.math.newRandomGenerator()
 +
randomNumber = rng:random(1,100)
 +
end
 +
</source>
 
== See Also ==
 
== See Also ==
 
* [[parent::love.math]]
 
* [[parent::love.math]]

Revision as of 03:04, 18 December 2013

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

Creates a new RandomGenerator object which is completely independent of other RandomGenerator objects and random functions.

Function

Synopsis

rng = love.math.newRandomGenerator( )

Arguments

None

Returns

RandomGenerator rng
A Random Number Generator object.

Function

See RandomGenerator:setState.

Synopsis

rng = love.math.newRandomGenerator( state )

Arguments

number state
The state ("seed") number to use for this instance of the object.

Returns

RandomGenerator rng
A Random Number Generator object.

Function

See RandomGenerator:setState.

Synopsis

rng = love.math.newRandomGenerator( low, high )

Arguments

number low
The lower 32 bits of the state number to use for this instance of the object.
number high
The higher 32 bits of the state number to use for this instance of the object.

Returns

RandomGenerator rng
A Random Number Generator object.

Examples

Creates a new RandomGenerator object, then generates a number between 1 and 100 inclusive.

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

See Also

Other Languages