C Program to Generate Random Numbers

For generating C random number, we will use the function random function provided by the C class that is rand(). Function rand() returns a pseudo-random number between 0 and rand_max.

What is Randon Number?

We can define Random as something that happens without any conscious decision. Similarly, a random number is a number that is chosen unpredictably or randomly from the set of numbers.

Similarly in this article, we will write a program for random number generator in c with the help of rand() function and the operator called modulus (%).

We will see two different programs:
1. Defining the range in a program
2. Taking the user’s Input

Program for C random number generator.

In this program, we will see how to generate 10 random numbers between 1 to 100 in C using the function rand(). And every time you run the code it generates different random numbers between this range.

The output for c random number generator:

Randim Number generator in c

Program to generate random number in C (user’s input)

This random number generator c is also similar, the only difference is that we will generate according to user choice. The program takes the maximum range up to which user wishes to generate a number and how many random number users want to generate between that range.

The output for c random number generator taking user’s input:

Random Number generator in c programming

Learn C programs