Introduction | Language Structure | IB Statements | File System | Comet 32 Runtime | Index |
| Syntax: | RND(numeric-argument) |
| Discussion: |
The RND function returns a pseudo-random value less than 1 but greater
than or equal to 0.
The returned value has a length/precision of 8.8 (i.e.,
all 8 digits are to the right of the decimal point).
The value of the numeric-argument determines how the RND function produces values:
To produce random integers in a given range, use this formula: INT((upperbound - lowerbound + 1) * RND(numeric-argument) + lowerbound)Here, upperbound is the highest number in the range, and lowerbound is the lowest number in the range. |
| History: | This function was added in Build 290. |
| Example 1: |
LENGTH 8.8 & LOCAL X . . . X = RND(0)In this example, X is assigned a pseudo-random number. Since the numeric-argument is 0, the same sequence will be returned each time this program is run (while the Comet session remains active). When Comet is terminated and re-started, a different sequence will be returned when this program is run. |
| Example 2: |
LENGTH 8.8 & LOCAL X . . . X = RND(1) ! Randomize the pseudo-random number generator . . . LABEL: X = RND(0) ! Generate a pseudo-random number . . . GOTO LABELIn this example, the RND(1) function randomizes the pseudo-random number generator. Further on in the program, the RND(0) function returns a series of pseudo-random numbers. |
| Example 3: |
LENGTH 2.0 LOCAL A,UPPER,LOWER . . . UPPER = 75 LOWER = 40 A = INT((UPPER-LOWER+1)*RND(0) + LOWER) The above example shows how to produce a random integer between 40 and 75. |