Wednesday, April 14, 2010

C Program to Generate Random Numbers

This is a simple program to generate random numbers.This logic can be used to build a Lotto program or a program to pick Lucky number and so on.Here’s the program






#include

#include

#include



int main(void)

{

int i;

time_t t;

srand((unsigned) time(&t));

printf(“Ten random numbers from 0 to 99\n\n”);

for(i=0; i<10;i++)

printf(“%d\n”,rand()%100);

}



OR



If it necessary to generate a number between 0 and (num-1) then this program meets the ideal solution

#include

#include

#include

/* prints a random number in the range 0 to 99 */

int main(void)

{

randomize();

printf(“Random number in the 0-99 range: %d\n”, random (100));

return 0;

}

0 comments:

Post a Comment