Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

9.06 Random Numbers

Generating Random Numbers

Generating random numbers using the Rnd() function. When you use random numbers, you normally want to tell the computer to generate a new random number sequence based upon some internal method (usually using the system clock). This still applies with Basic syntax. The Rnd() function has an optional parameter that lets you tell the computer to generate a new random number sequence. With Basic syntax, you can pass your own random number seed value to generate the sequence. This is beneficial if you are writing a report that uses random numbers and want to test it using the same random number sequence each time. If you pass the Rnd() function a positive number, it does just that. However, if you want your sequence to be different every time, and thus your report will have different numbers every time, pass the Rnd() function a negative number. This tells it to use the system clock to generate the random number sequence. This results in a pseudo-random sequence of numbers each time you call it. Once you have called Rnd() with a seed, call the Rnd() function without a seed to get the next random number in the sequence.