Introduction to C++ Programming
Learn C++ in step-by-step lessons.
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.
- Set the seed
- A range of values
- Rolling dice
Glossary for random lessonFull Glossary