Skip to content

Instantly share code, notes, and snippets.

@gboddin
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gboddin/00c97b29c76d48440fa0 to your computer and use it in GitHub Desktop.
Save gboddin/00c97b29c76d48440fa0 to your computer and use it in GitHub Desktop.
euromillion_gen.php
<?php
// or how to explain to compulsive gamer that ... random is ... not that random ...
$number_of_generation = isset($_GET['nb']) ? (int) $_GET['nb'] : 2;
header('Content-Type: text/plain');
for ($iteration = 0; $iteration < $number_of_generation ; $iteration++) {
echo implode(' - ', getUniqueNumberSequence(5, 1, 50));
echo ' * ';
echo implode(' - ', getUniqueNumberSequence(2, 1, 11));
echo PHP_EOL;
}
function getUniqueNumberSequence($count,$min,$max) {
$numbers = array();
for ($iteration_number = 0; $iteration_number < $count; $iteration_number++) {
$number = rand($min,$max);
if(in_array($number,$numbers)) {
//decrement counter, we already have that number
$iteration_number--;
} else {
$numbers[] = $number;
}
}
natsort($numbers);
return $numbers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment