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. Link to comment https://forums.phpfreaks.com/topic/120859-mt_rand-and-rand-always-returns-lowest-possible-number/ 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 Link to comment https://forums.phpfreaks.com/topic/120859-mt_rand-and-rand-always-returns-lowest-possible-number/#findComment-623001 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. Link to comment https://forums.phpfreaks.com/topic/120859-mt_rand-and-rand-always-returns-lowest-possible-number/#findComment-623078 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. Link to comment https://forums.phpfreaks.com/topic/120859-mt_rand-and-rand-always-returns-lowest-possible-number/#findComment-623084 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. Link to comment https://forums.phpfreaks.com/topic/120859-mt_rand-and-rand-always-returns-lowest-possible-number/#findComment-623118 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. Link to comment https://forums.phpfreaks.com/topic/120859-mt_rand-and-rand-always-returns-lowest-possible-number/#findComment-623182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.