Difference between revisions of "RandomGenerator:getState"
(Created page) |
|||
Line 1: | Line 1: | ||
− | + | {{newin|[[0.9.1]]|091|type=function}} | |
+ | Gets the current state of the random number generator. This returns an opaque implementation-dependent string which is only useful for later use with [[RandomGenerator:setState]]. | ||
+ | |||
+ | This is different from [[RandomGenerator:getSeed]] in that getState gets the RandomGenerator's current state, whereas getSeed gets the previously set seed number. | ||
+ | |||
+ | == Function == | ||
+ | === Synopsis === | ||
+ | <source lang="lua"> | ||
+ | state = RandomGenerator:getState( ) | ||
+ | </source> | ||
+ | === Arguments === | ||
+ | None. | ||
+ | === Returns === | ||
+ | {{param|string|state|The current state of the RandomGenerator object, represented as a string.}} | ||
+ | == Notes == | ||
+ | The value of the state string does not depend on the current operating system. | ||
+ | == Examples == | ||
+ | <source lang="lua"> | ||
+ | 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()) | ||
+ | </source> | ||
+ | == See Also == | ||
+ | * [[parent::RandomGenerator]] | ||
+ | * [[RandomGenerator:setState]] | ||
+ | [[Category:Functions]] | ||
+ | {{#set:Description=Gets the current state of the random number generator.}} | ||
+ | == Other Languages == | ||
+ | {{i18n|RandomGenerator:getState}} |
Revision as of 06:06, 16 February 2014
Available since LÖVE 0.9.1 |
This function is not supported in earlier versions. |
Gets the current state of the random number generator. This returns an opaque implementation-dependent string which is only useful for later use with RandomGenerator:setState.
This is different from RandomGenerator:getSeed in that getState gets the RandomGenerator's current state, whereas getSeed gets the previously set seed number.
Contents
Function
Synopsis
state = RandomGenerator:getState( )
Arguments
None.
Returns
string state
- The current state of the RandomGenerator object, represented as a string.
Notes
The value 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