Running the code with such a small number of trials will likely cause skewed
results one way or the other.
I ran this code and consistently got around the 50-50 split you'd expect:
<?php
$one = 0;
$zero = 0;
srand((double) microtime() * 1000000);
for ($i = 0; $i < 2000000; $i++)
{
if (rand(0, 1))
$one++;
else
$zero++;
}
print "Total: " . ($one + $zero) . "\n";
print "One: " . $one . "\n";
print "Zero: " . $zero . "\n";
?>
J
Andy wrote:
> Hi there,
>
> I am wondering if it is possible that this function tends to be more often
> 1. I do get 8 of 10 times 1.
>
> srand((double)microtime()*1000000);
> if (rand(0,1) == 1){
> code...
>
> it looks ok to me.
>
> Thanx for any help,
>
> Andy
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php