Random Numbers

Random numbers are very important if you want to create games.
You would not want to play a game of cards if the players always got exactly the same cards.

In C++, the function rand() returns an integer value that is >= 0.

We can use the mod operator % (remainder) to control the range of values. For instance num%6 will always give you a value from 0 to 5 no matter what the value of num is.

Please study the material at each of the links below.

  1. Display 3 random numbers
  2. Set the seed
  3. A range of values
  4. Rolling dice
Like us on Facebook:

OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher: Zebra0.com
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 18 2017 14:07:39.