October 2005
Intermediate to advanced
372 pages
11h 35m
English
mt_rand()
int mt_rand ( [intmin, intmax] )
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.