Returns a pseudorandom integral number in the range between 0
and RAND_MAX
This number is generated by an algorithm that returns a sequence of apparently nonrelated 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.
RAND_MAX is a constant defined in <cstdlib>
A typical way to generate trivial pseudorandom numbers in a determined range using rand is to use the modulo of the returned value by the range span and add the initial value of the range:


Notice though that this modulo operation does not generate uniformly distributed random numbers in the span (since in most cases this operation makes lower numbers slightly more likely).
[mai mult...]