# C program to generate random numbers within a range

**Random numbers** just numbers that lie within a range and any of the numbers can occur.

In programming, we come through a lot of scenarios where we need to **generate random numbers**. Like for dice games, lottery system, etc. In the c programming language, there is an inbuilt method to take care of this.

**srand()** and **rand()** functions are used to **generate random numbers**. Now, let's dig deep into these methods and understand their working.

### rand() function

The **rand() function** in the C programming language is used to generate a random number. The return type is of **rand() function** is an integer.

C code to generate a random numberOutput## srand() function

The

srand() functionis used to set the starting value for the series of random integers. You can use thesrand()to set the seed of the rand function to a different starting point.The parameters that are passed into the

srand() functionare the starting values for the rand method.C code to generate random numbers using srand()Output## Generating random numbers within a range

The

rand() functiongenerates random numbers that can be any integer value. But, togenerate random numbers within a specific range, we have a formula that returns a random number between given ranges.Formula:Program to generate random numbers from 1 to 6OutputExplanation:This program declares a variable num that generates a random number between 1 to 6. for doing this we will initialize the lower limit of the rand to 1 and The upper limit of the rand function to 6. this will generate a random number between 1 to 6 using the formula.

Program to generate random number between 1 to 100

need an explanation for this answer? contact us directly to get an explanation for this answerOutput