Zebra0.com

cpp randomIntroduction to C++ Programming

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.

  1. Display 3 random numbers

  2. Set the seed

  3. A range of values

  4. Rolling dice

GlossaryGlossary for random lesson
Full Glossary