# How do you generate a random number between 1 and 6 in C++?

rand() function in C++ returns a positive number within the range of 0.0 to rand_max(). the disadvantage of using this function is that if you generate many random numbers employing a loop, this function generates an equivalent sequence of numbers whenever the program is executed. However, if you would like to use this function to get different numbers whenever the program runs, you want to use srand() function with the rand() function.

**srand()****:** srand() function seeds a pseudo-random number generator that’s

employed by the rand() function. The default seed value for rand() is 1. Following is that the syntax for using srand():

**READ MORE:**