C++

C++ random number between 1 and 101 min read

In this post I’ll show you how to get random number between 1 and 10.

Before diving the example you shuld know what are srand and rand functions in C++.




rand: This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using function srand.

srand : This function sets the starting point for producing a series of pseudo-random integers. If srand() is not called, the rand() seed is set as if srand(1) were called at program start. Any other value for seed sets the generator to a different starting point.

C++ Random Number Between 1 and 10:

Output:

Leave a Comment