Core Function Random

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
 
<pre>
 
<pre>
Random( <expression>, <expression2> )
+
Random( <minValue>, <maxValue>, <flag> )
 
</pre>
 
</pre>
  
Line 31: Line 31:
 
Failure: Does not return a random number (if an expression is not properly defined).
 
Failure: Does not return a random number (if an expression is not properly defined).
  
==== Some Examples ====
+
=== Remarks ===
 +
 
 +
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 ====
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">

Revision as of 04:41, 13 March 2014

Random( <minValue>, <maxValue>, <flag> )

Contents

Description

Get a random number from the defined area.

Parameters

expression

A number, or a variable containing a number.

$var = 5;

expression2

A number, or a variable containing a number.

$var2 = 33;

Return Value

Success: Returns a random number.

Failure: Does not return a random number (if an expression is not properly defined).

Remarks

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