Skip to content

Instantly share code, notes, and snippets.

@brankoajzele
Created January 19, 2013 08:14
Show Gist options
  • Save brankoajzele/4571350 to your computer and use it in GitHub Desktop.
Save brankoajzele/4571350 to your computer and use it in GitHub Desktop.
Loto (random) number generator.
#!/usr/bin/php
<?php
/**
* Loto (random) number generator.
*
* Script accepts 3 params.
* First two are to determine the type of loto, for example 7 of 39, or 6 of 45.
* Third parameter is the number of combinations.
*
* By default it 7 of 39 and one combination.
*
* Setup: chmod +x loto.php
* Usage:
* ./loto.php
* ./loto.php 7 39 5
* ./loto.php 6 45 10
*/
function loto($x, $y) {
$loto = array();
while (count($loto) < $x) {
mt_srand();
$n = mt_rand(1, $y);
if (!in_array($n, $loto)) {
$loto[] = $n;
}
}
sort($loto);
return $loto;
}
$x = 7; /* 7 of 39, the 7 part */
$y = 39; /* 7 of 39, the 39 part */
$c = 1; /* number of combinations */
if (!empty($argv[1]) && !empty($argv[2])) {
$x = (int)$argv[1];
$y = $argv[2];
}
if (!empty($argv[3])) {
$c = (int)$argv[3];
}
if ($c > 1) {
for ($i=1; $i<=$c; $i++) {
echo implode(', ', loto($x, $y)); echo PHP_EOL;
}
} else {
echo implode(', ', loto($x, $y)); echo PHP_EOL;
}
echo 'Good luck :)'; echo PHP_EOL;
@sasi1346862
Copy link

Hiiii.....I need help..... I want last three digit number (RNG)...I HAVE PERVIOUS NUMBERS IF ANYONE CAN HELP ME.........PLEASE...... Waiting for the response.......

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment