W3cubDocs

/LÖVE

RandomGenerator:setState

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

Sets the current state of the random number generator. The value used as an argument for this function is an opaque implementation-dependent string and should only originate from a previous call to RandomGenerator:getState.

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.

Function

Synopsis

RandomGenerator:setState( state )

Arguments

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

Returns

Nothing.

Notes

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

Examples

rng = love.math.newRandomGenerator(os.time())
 
for i=1, 100 do
    -- Use some random numbers.
    rng:random()
end
 
-- Make a new RandomGenerator and set its state to the current state of the first one.
rng2 = love.math.newRandomGenerator()
rng2:setState(rng:getState())
 
-- Both 'rng' and 'rng2' will now give the same results. 
assert(rng:random() == rng2:random())

See Also

© 2006–2016 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/RandomGenerator:setState