C-programming-language

/* NOTE: This code has been coded with Borland C/C++ 3.0 */
//libraries
#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()

//main
int main()
{
//declaring a variable
int random;
//clearscreen
clrscr();

randomize();
random = random(100);

//display result
printf(”\nRandom numbers in the range 0-99: %d”,random);

//wait for a key to be pressed by user before program exits
getch();

}//end main

Note:

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 ;) )

Share This Article with your friends if you appreciate my effort to write it!

  Start Learning With Wakish - Enroll Freely Now! (Click Here!)

Share Wakish Wonderz On Facebook
SUBSCRIBE ⇒ ∑ [ EMAILRSS ] wakish.info

Posted in: World Of Programming

  (1) Comment so far - Be the 2nd to respond!

  1. 1
    From Gabriel BayNo Gravatar   on November 16th, 2009 at 6:18 pm

    how can we randomize number using probability?

Leave a Comment

Close
E-mail It