Core Function Random

From Sputnik Wiki
Revision as of 21:40, 11 August 2014 by UberFoX (Talk | contribs)
Jump to: navigation, search
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 number 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: Returns null.

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
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox