How to generate random number in C++

Recently I started learning C++. I should say that I enjoy the language very much and I am very interested in learning more deeply about computer programming. My friend suggested that CPP is the best program to get started with programming because it works too deep with computers.

As I was started learning, several questions came into my mind. One of them is how can I generate a random number using C++. Sorry for the very basic question. Can anyone help me?

You can use the rand() function to generate a random number in C++. Some examples are given below.

This will generate a random number between 1 and 99.

num1 = rand() % 100;

Generate a random number between 1 and 100

Just add 1 to the code.

num2 = rand() % 100 + 1;

100 can be replaced with any number of your choice to generate a random number between