Subscribe FREELY Right Now - click here!
/* NOTE: This code has been coded with Borland C/C++ 3.0 */
#include <stdio.h> //defines scanf() and printf()
#include <stdlib.h> //defines rand()
#include <time.h> //defines time() and is needed for randomize()
#include <conio.h> //defines clrscr() and getch()
//declaring a variable
random = random(100);
printf(“\nRandom numbers in the range 0-99: %d”,random);
//wait for a key to be pressed by user before program exits
1) The randomize() initialises the random number generator, rand(), with a value.
2) The code can work without the randomize() function, BUT without it your computer will only generate same number each time.
So, the randomize() is there to generate different random numbers with “time” and hence u need to include the library file <time.h>
3) The function rand(100) generates random numbers between 0 and (100-1). That is numbers between 0-99.
4) If you want to display 20 random numbers, just call the generator in a ‘for loop‘ with “counter <= 20“, like for(int counter=0;counter <= 20; counter++)
That’s all folks, simple huh? 🙂 (Yeah, but effective 😉 )