Difference between revisions of "RandomGenerator:setState"
(Created page) |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
{{newin|[[0.9.1]]|091|type=function}} | {{newin|[[0.9.1]]|091|type=function}} | ||
− | Sets the current state of the random number generator. The value used as an argument for this function is an opaque | + | 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. | 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. | ||
Line 35: | Line 35: | ||
* [[RandomGenerator:getState]] | * [[RandomGenerator:getState]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
− | {{#set:Description=Sets the current state of the random number generator.} | + | {{#set:Description=Sets the current state of the random number generator.}} |
== Other Languages == | == Other Languages == | ||
{{i18n|RandomGenerator:setState}} | {{i18n|RandomGenerator:setState}} |
Latest revision as of 21:30, 7 June 2019
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 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.
Contents
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
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info