6.6. Case Study: Random Number Generation


[Note: The random-number generation techniques shown in this section and Section 6.7 are included for readers who are not yet using C++11 compilers. In Section 6.8, we’ll present C++11’s improved random-number capabilities.]

We now take a brief and hopefully entertaining diversion into a popular programming application, namely simulation and game playing. In this and the next section, we develop a game-playing program that includes multiple functions.

The element of chance can be introduced into computer applications by using the C++ Standard Library function rand. Consider the following statement:

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.