0
i am trying to build a mega sena betting generator with the following parameters:
number of dozens and number of games
Rules:
- Numbers cannot duplicate between games.
- Consider the dozens between 00 and 59.
Final exit:
1 - Lista de jogos
2 - Lista de números que se repetiram mais de uma vez
Ex: Considering dozens quantity parameters = 7 and games = 2
Exit:
3 - 5 - 7 - 9 - 20 - 55 - 56
5 - 20-51 - 55 -56- 57 - 59
Duplicados:
55 - 2x
5 - 2x
Here’s the code I’ve built so far:
<?php
function getRandomNumbers($num, $min, $max, $repeat = false, $sort = false)
{
if ((($max - $min) + 1) >= $num) {
$numbers = array();
while (count($numbers) < $num) {
$number = mt_rand($min, $max);
if ($repeat || !in_array($number, $numbers)) {
$numbers[] = $number;
}
}
switch ($sort) {
case SORT_ASC:
sort($numbers);
break;
case SORT_DESC:
rsort($numbers);
break;
}
return $numbers;
}
return false;
}
?>
<?php
if ($numbers = getRandomNumbers(6, 1, 60, false, SORT_ASC)) {
print implode(', ', $numbers);
} else {
print 'A faixa de valores entre $min e $max deve ser igual ou superior à' .
' quantidade de números requisitados';
}
?>
however I cannot implement the restriction conditions, can help please?
The games are always 7 numbers?
– rray