Developer Documentation Library > Scripting > UNICOM Intelligence Function Library > Random number functions > Rnd
 
Rnd
This function returns a random decimal value. The numbers generated by this function are not true random numbers because they can be reproduced. However, the numbers generated meet general statistical standards of randomness.
Syntax
Rnd([Seed])
Parameters
Seed
Type: Long
The starting point to be used for generating the random number. The default is 0.
(return)
Type: Double
Random value >= 0 and < 1.0.
Remarks
If Seed is supplied, it is used to reset the starting point for the random number generator, as in SetRandomSeed, before the random number is generated.
If Seed is not supplied or has a value of 0, the function will use the starting point stored for the random number generator by the mrScriptBasic engine or Evaluate component and passed as a hidden parameter.
Each time you call one of the randomization functions, the starting point stored for the random number generator is updated. This means that if you call the function repeatedly without specifying the Seed parameter, the sequence of results is determined by the changing value passed as a hidden parameter. Specifying the Seed parameter is a way of resetting this sequence.
Example
This mrScriptBasic example uses the Rnd function to populate an array with random decimal values.
Dim i, random[10]

For i = 0 To 9
  random[i] = Rnd()
Next
Here are the output values:
0.9732556194067
0.790608546696603
4.03919452801347E-02
6.83862725272775E-02
0.985055443830788
1.80076491087675E-02
0.567231006920338
0.648117552511394
0.385062272660434
2.64703407883644E-02
See also
RanInt
Random number functions