Difference between revisions of "RAND()"

From Recital Documentation Wiki
Jump to: navigation, search
 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=RAND()=
 
 
 
==Class==
 
Numeric Data
 
 
 
 
==Purpose==
 
==Purpose==
 
Function to return a random number
 
Function to return a random number
Line 11: Line 4:
  
 
==Syntax==
 
==Syntax==
RAND(<expN>)
+
RAND([<expN>])
  
  
 
==See Also==
 
==See Also==
[[TMPNAM()]], [[SYS()]], [[GETPID()]]
+
[[GETPID()]], [[TMPNAM()]], [[SET COMPATIBLE]], [[SYS()]]  
  
  
 
==Description==
 
==Description==
The RAND() function returns a random number in the range 1 to 2147483647. The <expN> is included for FoxPro compatibility.
+
The RAND() function returns a number in the range 1 to 2147483647. Subsequent calls to RAND() will produce different numbers, but the sequence of numbers will be the same each time.
 +
 
 +
With SET COMPATIBLE set to FOXPRO | FOXBASE | VFP the number range is between 0 and 1 and 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.
  
  
Line 26: Line 21:
 
? rand()
 
? rand()
 
     31466
 
     31466
 +
 +
set compatible to foxpro
 +
? rand(-1)
 +
      0.66
 +
? rand()
 +
      0.73
 
</code>
 
</code>
  
  
 
==Products==
 
==Products==
Recital Database Server, Recital Mirage Server, Recital Terminal Developer
+
Recital, Recital Server
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 +
[[Category:Numeric Data]]
 +
[[Category:Numeric Data Functions]]

Latest revision as of 15:05, 7 December 2009

Purpose

Function to return a random number


Syntax

RAND([<expN>])


See Also

GETPID(), TMPNAM(), SET COMPATIBLE, SYS()


Description

The RAND() function returns a number in the range 1 to 2147483647. Subsequent calls to RAND() will produce different numbers, but the sequence of numbers will be the same each time.

With SET COMPATIBLE set to FOXPRO | FOXBASE | VFP the number range is between 0 and 1 and 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()
     31466
 
set compatible to foxpro
? rand(-1)
      0.66
? rand()
      0.73


Products

Recital, Recital Server