Generating a random number between two terminals in C++

In this tutorial, we'll see how to generate n random numbers. In C++, the function rand()is part of the stdlib, don't forget to import this library.

First, you need to initialize the position with the function time()  which returns the elapsed time in seconds since January 1, 1970, otherwise the sequence generated would be the same each time.

We chose to generate numbers between two bounds, lower and upper. The numbers returned are part of the interval [a, b] where is the lower bound and b and the upper bound. Just draw a number and then multiply it by (b-a+1) and divide the total on RAND_MAX which is the maximum value returned by the function rand().

Output:
Generate random number in C++ function rand time

References:
Openclassrooms: randomness in C and C++
cplusplus.com: time.h
cplusplus.com:  RAND_MAX