# Generate random numbers

Random numbers are always only pseudo-random numbers and are generated with a mathematical formula from the predecessor.

A random number can be generated by calling the `rand()` function. The function returns a different number each time it is called. The range of values in which the random number should be located can be specified.

``````#include &lt;iostream&gt;
using namespace std;

int main() {
// initialize random seed
srand (time(NULL));

cout << "Random value between 0 - 9:\t";
int randomInteger10 = rand() % 10 + 1;
cout << randomInteger10 << endl;

cout << "Random value between 0 - 99:\t";
int randomInteger100 = rand() % 100;
cout << randomInteger100 << endl;

cout << "Random value between 1 - 100:\t";
int randomInteger = rand() % 100 + 1;
cout << randomInteger << endl;

return 0;
}``````
##### Output first run
``````Random value between 0 - 9:	8
Random value between 0 - 99:	49
Random value between 1 - 100:	74``````
##### Output second run
``````Random value between 0 - 9:	1
Random value between 0 - 99:	66
Random value between 1 - 100:	92``````