Difference between revisions of "RandomGenerator:setSeed"

m (moved RandomGenerator:randomseed to RandomGenerator:setState: Function has been renamed and changed)
(Moved example from love.math.setRandomSeed)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{newin|[[0.9.0]]|090|type=function}}
 
{{newin|[[0.9.0]]|090|type=function}}
Seeds the random number generator with a specified number.
+
Sets the seed of the random number generator using the specified integer number.
 
 
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
RandomGenerator:randomseed( seed )
+
RandomGenerator:setSeed( seed )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|number|seed|The seed to use for this object.}}
+
{{param|number|seed|The integer number with which you want to seed the randomization. Must be within the range of [1, 2^53].}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
 +
=== Notes ===
 +
Due to Lua's use of double-precision floating point numbers, values above 2^53 cannot be accurately represented. Use the other variant of this function if your seed will have a larger value.
 +
== Function ==
 +
Combines two 32-bit integer numbers into a 64-bit integer value and sets the seed of the random number generator using the value.
 +
=== Synopsis ===
 +
<source lang="lua">
 +
RandomGenerator:setSeed( low, high )
 +
</source>
 +
=== Arguments ===
 +
{{param|number|low|The lower 32 bits of the seed value. Must be within the range of [0, 2^32 - 1].}}
 +
{{param|number|high|The higher 32 bits of the seed value. Must be within the range of [0, 2^32 - 1].}}
 +
=== Returns ===
 +
Nothing.
 +
== Examples ==
 +
Creates a new RandomGenerator object, sets the seed to the system clock's time, then generates a number between 1 and 100 inclusive. Note that the seed can be any number within the range of [0, 2^53 - 1].
 +
<source lang="lua">
 +
function love.load()
 +
rng = love.math.newRandomGenerator()
 +
rng:setSeed(os.time())
 +
randomNumber = rng:random(1,100)
 +
end
 +
</source>
 
== See Also ==
 
== See Also ==
 
* [[parent::RandomGenerator]]
 
* [[parent::RandomGenerator]]
* [[love.math.randomseed]]
+
* [[RandomGenerator:getSeed]]
 
* [[love.math]]
 
* [[love.math]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Seeds the random number generator with a specified number.}}
+
{{#set:Description=Sets the seed of the random number generator.}}
 
== Other Languages ==
 
== Other Languages ==
{{i18n|RandomGenerator:randomseed}}
+
{{i18n|RandomGenerator:setSeed}}

Latest revision as of 07:05, 18 December 2013

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

Sets the seed of the random number generator using the specified integer number.

Function

Synopsis

RandomGenerator:setSeed( seed )

Arguments

number seed
The integer number with which you want to seed the randomization. Must be within the range of [1, 2^53].

Returns

Nothing.

Notes

Due to Lua's use of double-precision floating point numbers, values above 2^53 cannot be accurately represented. Use the other variant of this function if your seed will have a larger value.

Function

Combines two 32-bit integer numbers into a 64-bit integer value and sets the seed of the random number generator using the value.

Synopsis

RandomGenerator:setSeed( low, high )

Arguments

number low
The lower 32 bits of the seed value. Must be within the range of [0, 2^32 - 1].
number high
The higher 32 bits of the seed value. Must be within the range of [0, 2^32 - 1].

Returns

Nothing.

Examples

Creates a new RandomGenerator object, sets the seed to the system clock's time, then generates a number between 1 and 100 inclusive. Note that the seed can be any number within the range of [0, 2^53 - 1].

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

See Also

Other Languages