Turbo C - randomize, rand and srand functions for generating random numbers
I have explained about randomize, rand and srand functions for generating random numbers. The random numbers are useful in animation or to guess a number from your computer program.
Then why do we need 3 functions? rand() is the function which does get the random number. If you need a narrow range then you can use mod % operator to bring it down to your range. What would be starting point for random number generation. If you need different random number sequence, then you have make a call to randomize() function that will take input from the system clock. If you want to repeat the same set of random number, then you can use srand by passing the seed as an input.
The random numbers are given extensively in the following graphics animation programs.
Turbo C Graphics - Using Circle and setcolor, setbkcolor functions
Turbo C Graphics - Using bar and setfillstyle functions
Turbo C Graphics - Using line and setlinestyle functions
Source Code
Refer to the above links for source code
Output
None
|