﻿ RAND( ) Function js editor     Web development ﻿

Main Page        Returns a random number between 0 and 1.

`RAND([nSeedValue])`

#### Parameters

nSeedValue

Specifies the seed value that determines the sequence of values RAND(В ) returns. RAND(В ) returns the same sequence of random numbers if you use the same seed value for nSeedValue the first time you issue RAND(В ) followed by subsequent RAND(В ) function calls without nSeedValue. If nSeedValue is negative the first time you issued RAND(В ), a seed value from the system clock is used. To achieve the most random sequence of numbers, issue RAND(В ) initially with a negative argument and then issue RAND(В ) without an argument. If you omit nSeedValue, RAND(В ) uses a default seed value of 100,001.

Numeric

# Example

The first example below uses RAND(В ) to create a table with 10 records containing random values, then uses MIN(В ) and MAX(В ) to display the maximum and minimum values in the table.

The second example below displays a random number that falls between two values, 1 and 10.

В Copy Code
```CLOSE DATABASES
CREATE TABLE Random (cValue N(3))
FOR nItem = 1 TO 10  && Append 10 records,
APPEND BLANK
REPLACE cValue WITH 1 + 100 * RAND( )  && Insert random values
ENDFOR

CLEAR
LIST  && Display the values
gnMaximum = 1  && Initialize minimum value
gnMinimum = 100  && Initialize maximum value
SCAN
gnMinimum = MIN(gnMinimum, cValue)
gnMaximum = MAX(gnMaximum, cValue)
ENDSCAN
? 'The minimum value is: ', gnMinimum  && Display minimum value
? 'The maximum value is: ', gnMaximum  && Display maximum value

CLEAR
gnLower = 1
gnUpper = 10

? INT((gnUpper - gnLower + 1) * RAND( ) + gnLower)```

# See Also js editor     Web development ﻿