Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

Name

mt_rand()

Synopsis

    int mt_rand ( [int min, int max] )

The mt_rand() function returns random numbers, similar to the rand(). However, it uses the Mersenne Twister algorithm to generate "better" random numbers (i.e., more random), and is often preferred.

If you supply no parameters, mt_rand() will return a number between 0 and mt_getrandmax(). If you supply it with two parameters, mt_getrandmax() will use those as the upper and lower limits for the random number it generates. The limits are inclusive: if you specify 1 and 3, your random number could be 1, 2, or 3.

    $mtrand = mt_rand();
    $mtrandrange = mt_rand(1,100);

The maximum value that can be generated by mt_rand() varies depending on the system you use, but on both Windows and Unix, the default is 2,147,483,647.

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.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page