Difference between revisions of "RandomGenerator:random"

(Created page with "{{newin|0.9.0|090|type=function}} Generates a pseudo random number in a platform independent way. == Function == Get uniformly distributed pseudo random number in [0,1]. ===...")
 
(https://www.lua.org/pil/18.html)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{newin|[[0.9.0]]|090|type=function}}
 
{{newin|[[0.9.0]]|090|type=function}}
Generates a pseudo random number in a platform independent way.
+
Generates a pseudo-random number in a platform independent manner.
  
 
== Function ==
 
== Function ==
Get uniformly distributed pseudo random number in [0,1].
+
Get uniformly distributed pseudo-random real number within [0, 1).
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 11: Line 11:
 
None.
 
None.
 
=== Returns ===
 
=== Returns ===
{{param|number|number|The pseudo random number.}}
+
{{param|number|number|The pseudo-random number.}}
  
 
== Function ==
 
== Function ==
Get uniformly distributed pseudo random number in [0,max]
+
Get uniformly distributed pseudo-random '''integer''' number within [1, max].
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 22: Line 22:
 
{{param|number|max|The maximum possible value it should return.}}
 
{{param|number|max|The maximum possible value it should return.}}
 
=== Returns ===
 
=== Returns ===
{{param|number|number|The pseudo random number.}}
+
{{param|number|number|The pseudo-random integer number.}}
 
== Function ==
 
== Function ==
Get uniformly distributed pseudo random number in [min, max].
+
Get uniformly distributed pseudo-random '''integer''' number within [min, max].
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 33: Line 33:
 
{{param|number|max|The maximum possible value it should return.}}
 
{{param|number|max|The maximum possible value it should return.}}
 
=== Returns ===
 
=== Returns ===
{{param|number|number|The pseudo random number.}}
+
{{param|number|number|The pseudo-random integer number.}}
 
+
== Notes ==
 +
When using the 2nd and 3rd variant, numbers passed will be rounded, thus, <code>RandomGenerator:random(0, 76.767)</code> may return 77
 
== See Also ==
 
== See Also ==
 
* [[parent::RandomGenerator]]
 
* [[parent::RandomGenerator]]
Line 40: Line 41:
 
* [[love.math]]
 
* [[love.math]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Generates a pseudo random number in a platform independent way.}}
+
{{#set:Description=Generates a pseudo-random number in a platform independent manner.}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|RandomGenerator:random}}
 
{{i18n|RandomGenerator:random}}

Latest revision as of 15:07, 26 April 2021

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

Generates a pseudo-random number in a platform independent manner.

Function

Get uniformly distributed pseudo-random real number within [0, 1).

Synopsis

number = RandomGenerator:random( )

Arguments

None.

Returns

number number
The pseudo-random number.

Function

Get uniformly distributed pseudo-random integer number within [1, max].

Synopsis

number = RandomGenerator:random( max )

Arguments

number max
The maximum possible value it should return.

Returns

number number
The pseudo-random integer number.

Function

Get uniformly distributed pseudo-random integer number within [min, max].

Synopsis

number = RandomGenerator:random( min, max )

Arguments

number min
The minimum possible value it should return.
number max
The maximum possible value it should return.

Returns

number number
The pseudo-random integer number.

Notes

When using the 2nd and 3rd variant, numbers passed will be rounded, thus, RandomGenerator:random(0, 76.767) may return 77

See Also

Other Languages