C Program to generate random numbers.

C Program to generate random numbers. Random Numbers are numbers which are produced by a process and its outcome is unpredictable.The function srand() is used to seed the random sequence. The rand() function shall compute a sequence of pseudo-random integers in the range [0, {RAND_MAX}] with a period of at least 2^32.
Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main() {
int i, num;
printf("Enter how many random numbers you want?n");
scanf("%d", &num);
//The function srand() is used to seed the random sequence.
//srand() will generate a specific "random" sequence over and over again.
srand(time(NULL));
//The rand() function shall compute a sequence of pseudo-random
//integers in the range [0, {RAND_MAX}] with a period of at least 2^32.
for (i = 0; i < num; i++) {
printf("random_number[%d]= %dn", i + 1, rand());
}

printf("A number between 0 and 99: %dn", rand() % 100);

printf("A number between 0 and 9: %dn", rand() % 10);

return 0;
}
Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

Leave a Reply