Page 1 of 1

some help for a beginner

Posted: Sat Oct 09, 2010 5:41 am
by gustoid
Hi,

I am attempting to generate two sets of random numbers, and have them pair up with no conflitcs.

the end result would look something like this:
1 5
2 3
5 1
4 2
3 4

I have the first set of numbers created, but I can't seem to figure out how to generate a second set and match them as shown above.

<?php
$numbers = array("1 ", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ", "9 ", "10 ", "11 ", "12 ");
shuffle($numbers);
foreach ($numbers as $number) {
echo "$number ";
echo "<br />";
}
?>
Any help would be appreciated.

Thanks

Re: some help for a beginner

Posted: Sat Oct 09, 2010 8:41 am
by twinedev
Is this what you were looking for?

Code: Select all

$intCount = count($numbers);
for($t=0;$t<$intCount;$t=$t+2) {
    echo $numbers[$t},'  ',$numbers[$t+1],"\n";
}
or

Code: Select all

$intHalf = count($numbers)/2;
for($t=0;$t<$intHalf;$t++) {
    echo $numbers[$t},'  ',$numbers[$t+$intHalf],"\n";
}
-Greg