Random Number Generator in C

Random Number Generator in C

Here, you will get the program code to make a Random Number Generator in C programming. To generate a random number in c programming, we can use random function.

random number generator in c

 

What is Random Number

Random number is a number that is generated by a process, that has no specific pattern or order.

What is the formula for random numbers

Random numbers in c, can be generated by using the rand() function. This random function is a built in function, which is defined in the <stdlib.h> header file. It returns a pseudo-random number between 0 and RAND_MAX.

int rand(); 

The rand() function returns a positive random number(between 0 to RAND_MAX).

Difference Between rand() and srand() functions 

 

rand()

srand()

rand() is a function that generates a random number each time it is called.The function srand() establishes the beginning point for producing a series of random integers.
● It does not require any input parameter.● It requires a seed as an input parameter which is used to generate the random numbers.
● It can be called any time in the program.
● It is called only once in program to initialize the starting point value of seed.
● It return random number, when called.
● No return any value.
● The seed can be provided using the time() function.

Program #1. Random Number Generator in C

Output

Random number : 16582

 

Program #2 :- Generate 10 Random Numbers

Output

random number generator program output

 

 

 

Check out our other C programming Examples

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top