Core Function Random
(→Remarks) |
|||
Line 9: | Line 9: | ||
=== Parameters === | === Parameters === | ||
− | + | == minValue == | |
− | A number, or a variable containing a number. | + | Optional; A number, or a variable containing a number. |
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
Line 17: | Line 17: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | == maxValue == | |
− | A number, or a variable containing a number. | + | Optional; A number, or a variable containing a number. |
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
Line 25: | Line 25: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | == flag == | |
− | Type of random to generate. | + | Optional; Type of random to generate. |
<pre> | <pre> |
Revision as of 22:48, 26 July 2014
Random( <minValue>, <maxValue>, <flag> )
Contents |
Description
Get a random number from the defined area.
Parameters
minValue
Optional; A number, or a variable containing a number.
$var = 5;
maxValue
Optional; A number, or a variable containing a number.
$var2 = 33;
flag
Optional; Type of random to generate.
0 = Generate an integer (Int32) random number and store return value as a Double 1 = Generate an integer (Int32) random number and store return value as an Int32 2 = Generate an integer (Int64) random number and store return value as an Int64 3 = Generate an integer (Int64) random number and store return value as a Double
Default: Generate a random double number (min: 0, max: 1) and store return value as a Double
Return Value
Success: Returns a random number.
Failure: Does not return a random number (if an expression is not properly defined).
Remarks
If you only use the first or first two (or none) params then the generated value and its return will both by a Double not an integer to obtain an integer you must specifically set so in the flags.
Warning:
The lower bound is inclusive and the upper bound is exclusive.
That means that Random() will return the lower number, but it is guaranteed to never return the upper one.
This means if you wish to generate a random number from 1 to 3 you must request from 1 to 4.
The same goes if you wish to generate a random number from 0.1 to 0.3 you must request from 0.1 to 0.4.
Example
$var = 5; // first expression $var2 = 33; // second expression $ran = Random($var, $var2); // function in variable printf($ran); // print a random number from $ran