Difference between revisions of "love.math.newRandomGenerator"

(Updated for state/seed changes)
m (Function: - Move notes section so it's in the correct order.)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{newin|[[0.9.0]]|090|type=function}}
 
{{newin|[[0.9.0]]|090|type=function}}
Creates a new [[RandomGenerator]] that is completely independent of other [[RandomGenerator]] objects or other random functions.
+
Creates a new [[RandomGenerator]] object which is completely independent of other RandomGenerator objects and random functions.
  
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
rng = love.graphics.newRandomGenerator( )
+
rng = love.math.newRandomGenerator( )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
 
None
 
None
 
=== Returns ===
 
=== Returns ===
{{param|RandomGenerator|rng|A Random Number Generator object.}}
+
{{param|RandomGenerator|rng|The new Random Number Generator object.}}
 +
=== Notes ===
 +
The default seed used in version 11.x is the following low/high pair: 0xCBBF7A44, 0x0139408D.
  
 
== Function ==
 
== Function ==
See [[RandomGenerator:setState]].
 
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
rng = love.graphics.newRandomGenerator( state )
+
rng = love.math.newRandomGenerator( seed )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|number|state|The state ("seed") number to use for this instance of the object.}}
+
{{param|number|seed|The initial seed number to use for this object.}}
 
=== Returns ===
 
=== Returns ===
{{param|RandomGenerator|rng|A Random Number Generator object.}}
+
{{param|RandomGenerator|rng|The new Random Number Generator object.}}
 +
=== Notes ===
 +
See [[RandomGenerator:setSeed]].
  
 
== Function ==
 
== Function ==
See [[RandomGenerator:setState]].
 
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
rng = love.graphics.newRandomGenerator( low, high )
+
rng = love.math.newRandomGenerator( low, high )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|number|low|The lower 32 bits of the state number to use for this instance of the object.}}
+
{{param|number|low|The lower 32 bits of the seed number to use for this object.}}
{{param|number|high|The higher 32 bits of the state number to use for this instance of the object.}}
+
{{param|number|high|The higher 32 bits of the seed number to use for this object.}}
 
=== Returns ===
 
=== Returns ===
{{param|RandomGenerator|rng|A Random Number Generator object.}}
+
{{param|RandomGenerator|rng|The new Random Number Generator object.}}
 +
=== Notes ===
 +
See [[RandomGenerator:setSeed]].
  
 +
== 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]]
 
* [[Constructs::RandomGenerator]]
 
* [[Constructs::RandomGenerator]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Creates a new [[RandomGenerator]].}}
+
{{#set:Description=Creates a new [[RandomGenerator]] object.}}
 
== Other Languages ==
 
== Other Languages ==
{{i18n|love.graphics.newRandomGenerator}}
+
{{i18n|love.math.newRandomGenerator}}

Latest revision as of 19:21, 23 November 2020

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
The new Random Number Generator object.

Notes

The default seed used in version 11.x is the following low/high pair: 0xCBBF7A44, 0x0139408D.

Function

Synopsis

rng = love.math.newRandomGenerator( seed )

Arguments

number seed
The initial seed number to use for this object.

Returns

RandomGenerator rng
The new Random Number Generator object.

Notes

See RandomGenerator:setSeed.

Function

Synopsis

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

Arguments

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

Returns

RandomGenerator rng
The new Random Number Generator object.

Notes

See RandomGenerator:setSeed.

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