jonsjava Posted July 28, 2008 Share Posted July 28, 2008 I got curious one day, so I wrote a small script that would run rand(1,1000) and mt_rand(1,000) 1,000,000 times each, and calculated the average. I had assumed that over time, the average would be somewhere around 500 (for every high, you would get a low). Well, the crazy thing is that it would hit 250 average every time, no matter the function (rand or mt_rand). I'm talking about within a decimal place of being exactly 250 for the average. That doesn't sound too random. So, the question: is there a class that is built for creating randoms that works better than the built-in random functions? If so, please point me to where I can find that. Thanks. Link to comment https://forums.phpfreaks.com/topic/116983-something-better-than-rand-or-mt_rand/ Share on other sites More sharing options...
samshel Posted July 28, 2008 Share Posted July 28, 2008 <?php error_reporting(7); $intCount = 1000000; $intSum = 0; for($i=0;$i<$intCount;$i++) { $intSum = $intSum + rand(1, 1000); } echo $intSum."--"; echo $intSum/$intCount; ?> this code gives me average as 500.something...as expected...same with mt_rand() Link to comment https://forums.phpfreaks.com/topic/116983-something-better-than-rand-or-mt_rand/#findComment-601625 Share on other sites More sharing options...
waynew Posted July 28, 2008 Share Posted July 28, 2008 Nothing is truly random. Link to comment https://forums.phpfreaks.com/topic/116983-something-better-than-rand-or-mt_rand/#findComment-601644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.