jordanwb Posted August 22, 2008 Share Posted August 22, 2008 If I call mt_rand like so: print mt_rand (0, 10); It returns 0 and always 0. If I call mt_rand like so: print mt_rand (1, 10); It returns 1 and always 1. I'm running Gentoo with all the latest available packages. The same goes for the rand function. Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 22, 2008 Share Posted August 22, 2008 Try running http://www.php.net/manual/en/function.mt-srand.php before using mt_rand Quote Link to comment Share on other sites More sharing options...
jordanwb Posted August 22, 2008 Author Share Posted August 22, 2008 Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically. So there's no need, but I'll try it anyways. It sortof worked. <?php mt_srand (microtime ()); for ($i = 0; $i < 100; $i++) { print mt_rand (0, 9000)."<br />"; } ?> It kept printing the same list each time I refreshed. Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 i had this problem on my local server, and never did quite figure out why it was happening. try uploading the script to a server somewhere and look again - i'm willing to bet you'll find it works okay on an external server. Quote Link to comment Share on other sites More sharing options...
jordanwb Posted August 22, 2008 Author Share Posted August 22, 2008 i'm willing to bet you'll find it works okay on an external server. I'm sure it will. Maybe I'll ask on the Gentoo forum. Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 22, 2008 Share Posted August 22, 2008 I did a quick search in PHP documentation, whether there's any setting that could control it, but couldn't find anything. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.