Last active
August 29, 2015 14:23
-
-
Save gboddin/00c97b29c76d48440fa0 to your computer and use it in GitHub Desktop.
euromillion_gen.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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