A Random Number Function
Now let's look at a function that makes use of an external static variable: a random number function. The ANSI C library provides the rand() function to generate random numbers. There are a variety of algorithms for generating random numbers, and ANSI C enables implementors to choose the best algorithm for a particular machine. However, the ANSI C standard also supplies a standard, portable algorithm that produces the same random numbers on different systems. Actually, rand() is a "pseudorandom number generator," meaning that the actual sequence of numbers is predictable (computers are not known for their spontaneity), but the numbers are spread pretty uniformly over the possible range of values.
Instead of using your ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access