NancyJ

03-28-2009, 03:36 PM

I'm writing a script to help me pick lottery numbers. Its supposed to come up with the most common individual numbers and most common combinations but its coming up with a strange result.

There are approx 14 million possible combinations, out of 100,000 loops I would expect most of those 100,000 to be unique combinations but what I'm actually getting (and its the same every time I run it) is that it only comes out with 5174 unique combinations (and its that exact same number every time). Roughly half the combinations come out 20 times and the other half come out 19 times. So either this is just a quirk of the random number generator or theres something wrong with my code.

for($i=0;$i<100000;$i++)

{

$comb =array(0);

$n=0;

for($j=0;$j<6;$j++)

{

while(in_array($n,$comb))

{

$n = rand(1,49);

}

$numbers[$n]++;

$comb[]=$n;

}

asort($comb);

$combinations[implode(',',$comb)]++;

}

echo count($combinations);

arsort($numbers);

arsort($combinations);

print_r($numbers);

print_r($combinations);

Update: Looks like it works fine on a real server. I blame windows.

There are approx 14 million possible combinations, out of 100,000 loops I would expect most of those 100,000 to be unique combinations but what I'm actually getting (and its the same every time I run it) is that it only comes out with 5174 unique combinations (and its that exact same number every time). Roughly half the combinations come out 20 times and the other half come out 19 times. So either this is just a quirk of the random number generator or theres something wrong with my code.

for($i=0;$i<100000;$i++)

{

$comb =array(0);

$n=0;

for($j=0;$j<6;$j++)

{

while(in_array($n,$comb))

{

$n = rand(1,49);

}

$numbers[$n]++;

$comb[]=$n;

}

asort($comb);

$combinations[implode(',',$comb)]++;

}

echo count($combinations);

arsort($numbers);

arsort($combinations);

print_r($numbers);

print_r($combinations);

Update: Looks like it works fine on a real server. I blame windows.