So I am working on my Final Project for a web application development class I'm taking and I am creating a Powerball lottery generator. For this to work, the White ball numbers cannot be duplicated. Here is how my code is looking so far:
<?php
for($x = 1; $x < 6; $x++){
//set each white ball variable (a through e) to a random number between 1 and 69
$a = floor((lcg_value() * 69 + 1));
$b = floor((lcg_value() * 69 + 1));
$c = floor((lcg_value() * 69 + 1));
$d = floor((lcg_value() * 69 + 1));
$e = floor((lcg_value() * 69 + 1));
//set powerball number variable to a number between 1 and 26
$f = floor((lcg_value() * 26 + 1));
//echo all white ball numbers and powerball number
echo "<b><u>Set #" . $x . "</u></b> - <b>White ball numbers are: </b>" . $a . " , " . $b . " , " . $c . " , " . $d . " , " . $e . ". <b>Powerball Number is </b>" . $f . ".<br />";
};
?>
The issue with this code is that there is a chance that variables 'a' through 'e' have a chance of being duplicate numbers. What code could I use to ensure that none of the variables 'a' through 'e' are the same? I thought of doing something like:
if($a != $b || $a != $c || $a || $d...){
//echo numbers
}else{
//generate new numbers
};
But that is just too much work and I always try to find the most efficient ways to write code. I don't want to have to write more code than I need to. Any assistance would be greatly appreciated. Thank you in advance!