Difference between revisions of "RAND()"
From Lianjapedia
Yvonne.milne (Talk | contribs) |
|||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
==Purpose== | ==Purpose== | ||
Function to return a random number | Function to return a random number | ||
− | |||
==Syntax== | ==Syntax== | ||
RAND([<expN>]) | RAND([<expN>]) | ||
− | |||
==See Also== | ==See Also== | ||
− | [[GETPID()]], [[TMPNAM() | + | [[GETPID()]], [[TMPNAM()]], [[SYS()]] |
− | + | ||
==Description== | ==Description== | ||
− | The RAND() function returns a number | + | The RAND() function returns a number between 0 and 1 with 2 decimal places (or the number of decimal places specified by [[SET DECIMALS]]). Subsequent calls to RAND() will produce different numbers, but the sequence of numbers will be the same each time. |
− | + | ||
− | + | ||
+ | A seed can be specified in <expN>. Using the same positive value in <expN> and omitting it in subsequent calls to the RAND() function will return the same sequence of numbers. Using a negative value in <expN> creates a seed based on the system clock, so subsequent RAND() calls will produce a different sequence of values. | ||
==Example== | ==Example== | ||
<code lang="recital"> | <code lang="recital"> | ||
− | |||
− | |||
− | |||
− | |||
? rand(-1) | ? rand(-1) | ||
− | 0. | + | 0.70 |
? rand() | ? rand() | ||
− | 0. | + | 0.61 |
</code> | </code> | ||
− | |||
− | |||
− | |||
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
− | |||
[[Category:Numeric Data Functions]] | [[Category:Numeric Data Functions]] |
Latest revision as of 05:50, 19 November 2013
Contents
Purpose
Function to return a random number
Syntax
RAND([<expN>])
See Also
Description
The RAND() function returns a number between 0 and 1 with 2 decimal places (or the number of decimal places specified by SET DECIMALS). Subsequent calls to RAND() will produce different numbers, but the sequence of numbers will be the same each time.
A seed can be specified in <expN>. Using the same positive value in <expN> and omitting it in subsequent calls to the RAND() function will return the same sequence of numbers. Using a negative value in <expN> creates a seed based on the system clock, so subsequent RAND() calls will produce a different sequence of values.
Example
? rand(-1) 0.70 ? rand() 0.61