Why you might not want to use PHP’s rand() function anymore

If you have been using the rand() function in PHP to generate random numbers for use in your scripts, you might want to consider otherwise. Maybe C programmers might also want a rethink since the PHP rand() function is derived from libc…

Anyway, help is at hand with the mt_rand() function which is syntactically similar but it behaves better. The numbers generated will be more, erm, random. You will also be able to improve random number generation performance by 4 times! Incidentally, the “mt” in “mt_rand()” stands for Mersenne-Twister.

If you are interested in the mathematics behind this, go to this site.

Leave a Reply

Your email address will not be published. Required fields are marked *