rand function (<cstdlib>)
i = rand();
Generates unsigned integer between 0 and RAND_MAX (usually
32767)
Scaling
and shifting
Modulus
(remainder) operator: %
10 % 3 is 1
x % y is between 0
and y 1
Example
i = rand() % 6 + 1;
Rand() % 6 generates a number between 0 and 5 (scaling)
+ 1 makes the range 1 to 6 (shift)
Next:
program to roll dice