August 2012
Intermediate to advanced
976 pages
30h 17m
English
The random-number engines are function-object classes (§ 14.8, p. 571) that define a call operator that takes no arguments and returns a random unsigned number. We can generate raw random numbers by calling an object of a random-number engine type:
default_random_engine e; // generates random unsigned integersfor (size_t i = 0; i < 10; ++i) // e() "calls" the object to produce the next random number cout << e() << " ";
On our system, this program generates:
16807 282475249 1622650073 984943658 1144108930 470211272 ...
Here, we defined an object named e that has type default_random_engine
. Inside the for, we call the object e to obtain the next random number.
The library defines several random-number ...
Read now
Unlock full access