13.2. Random Numbers

The following functions help you generate pseudorandom numbers. There are wrappers for the randomizing functions offered by your operating system, and there are functions based on the Mersenne Twister algorithm. The Mersenne Twister functions are faster and return numbers with a much better distribution suitable for cryptographic applications. The algorithm was developed by Makoto Matsumoto and Takuji Nishimura. You can read more about it on their Web page <http://www.math.keio.ac.jp/~matumoto/emt.html>. Pedro Melo refactored an implementation by Shawn Cokus in order to add support to PHP.

Pseudorandom number generators need seeding. Traditionally, the program seeds the generator itself, but PHP can handle this task. For ...

Get Core PHP Programming, Third 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.