samedi 31 janvier 2015

6 different random unique numbers php [duplicate]


This question already has an answer here:




I have generated in an array 6 random numbers using the rand () function. I would like to ensure that none of these numbers are duplicates. I have written:



$lucky_numbers = array (rand (1,50), rand (1,50),rand (1,50),rand (1,50),rand (1,50),rand (1,50));
if ($lucky_numbers[0] == $lucky_numbers[1]) {
print "same"; $lucky_numbers[1]++;
}
if ($lucky_numbers[1] > 50) {
$lucky_numbers[1]= $lucky_numbers[1]- 6;
}


and then checked each consecutive number with a similar code. But something doesn´t work. Any ideas ? Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire