Difference between revisions of "Core.random"

From GiderosMobile
m
m
Line 3: Line 3:
  
 
=== Description ===
 
=== Description ===
Generate and return a pseudo random number. The random number sequence is guaranteed to be consistent across devices for a given seed.
+
Generates and returns a pseudo random number. The random number sequence is guaranteed to be consistent across devices for a given seed.
 +
<source lang="lua">
 +
() = Core.random(generator,bound1,bound2)
 +
</source>
  
 
If bounds aren't specified, the function will return a floating point number between 0 and 1.
 
If bounds aren't specified, the function will return a floating point number between 0 and 1.
 
If one bound is specified, the function will return an integer number between 1 and that bound (inclusive).
 
If one bound is specified, the function will return an integer number between 1 and that bound (inclusive).
 
If both bounds are specified, the function will return an integer between bound1 and bound2. bound2 must be greater than bound1.
 
If both bounds are specified, the function will return an integer between bound1 and bound2. bound2 must be greater than bound1.
 
<source lang="lua">
 
() = Core.random(generator,bound1,bound2)
 
</source>
 
  
 
=== Parameters ===
 
=== Parameters ===
 
'''generator''': (number) PRNG algorithm to use, use 0 for default engine (MT19937) '''optional'''<br/>
 
'''generator''': (number) PRNG algorithm to use, use 0 for default engine (MT19937) '''optional'''<br/>
'''bound1''': (number) First bound of the range returned number must be in '''optional'''<br/>
+
'''bound1''': (number) first bound of the range returned number must be in '''optional'''<br/>
'''bound2''': (number) Second bound of the range returned number must be in '''optional'''<br/>
+
'''bound2''': (number) second bound of the range returned number must be in '''optional'''<br/>
  
 
=== Return values ===
 
=== Return values ===
 
'''Returns''' () random number<br/>
 
'''Returns''' () random number<br/>
 
  
 
{{Core}}
 
{{Core}}

Revision as of 00:35, 26 April 2021

Available since: Gideros 2017.9
Class: Core

Description

Generates and returns a pseudo random number. The random number sequence is guaranteed to be consistent across devices for a given seed.

() = Core.random(generator,bound1,bound2)

If bounds aren't specified, the function will return a floating point number between 0 and 1. If one bound is specified, the function will return an integer number between 1 and that bound (inclusive). If both bounds are specified, the function will return an integer between bound1 and bound2. bound2 must be greater than bound1.

Parameters

generator: (number) PRNG algorithm to use, use 0 for default engine (MT19937) optional
bound1: (number) first bound of the range returned number must be in optional
bound2: (number) second bound of the range returned number must be in optional

Return values

Returns () random number