17.4. Random Numbers
Programs often need a source of random numbers. Prior to the new standard, both C and C++ relied on a simple C library function named rand
. That function produces pseudorandom integers that are uniformly distributed in the range from 0 to a system-dependent maximum value that is at least 32767.
The rand
function has several problems: Many, if not most, programs need random numbers in a different range from the one produced by rand
. Some applications require random floating-point numbers. Some programs need numbers that reflect a nonuniform distribution. Programmers often introduce nonrandomness when they try to transform ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.