In any case, I think it may be a good idea to instead of going directly to a print the number groups were put into an array and subsequent groups checked for uniqueness before adding them to the array
Easiest way would be to use recursion, and strip off the previously attained numbers
$baseArray = array();
LotteryNumbers($baseArray, 6);
function LotteryNumbers($previousNumbers, $setLimit) {
$numberRange = range(1, 49);
// strip off any previous numbers, shuffle and get first six
$numbers = array_diff($numberRange, $previousNumbers);
shuffle($numbers);
$numbers = array_slice($numbers, 0, 6);
if (count($previousNumbers) == 0) print "Winning numbers: " . PHP_EOL;
foreach ($numbers as $number => $winning_numbers) {
print $winning_numbers . " ";
}
print PHP_EOL;
// combine previous array and this one to see how many numbers have been found
$allNumbers = array_merge($numbers, $previousNumbers);
if ((count($allNumbers) / 6) < 6) {
LotteryNumbers($allNumbers, $setLimit);
}
}
You’d have to put this in a different array, or the 2nd time you try to run it, you’ll get unexpected results since the array will have been cut down to the six elements from the first slice…
Noooo, because that would still only leave six elements left in the array. The first number is the starting element in the array, the second is how many to slice off.
But if you put it into a new element, you can continually slice off the same array without having to regen the numbers nor check for dupes. So, slightly altering your approach, this would work…
Though as a caveat, this approach will only randomize the list of numbers once, so it’s like dealing blackjack without shuffling the cards each time…it could be gamed