There are a couple of ways to go about it. The simplest is to create an array of all possible numbers, shuffle the array, then either pop or shift off the required number of choices. (In PHP, you can do the shuffling with array_rand().) Since pseudorandom number generators are far from perfect (and array_rand() uses mt_rand()), this doesn't actually create an "every ticket can win" scenario. Slightly (and only slightly) more complex, but likely to be fairer, is to create two different shuffled arrays of the numbers, pop or shift off the required number of selections from one array and use that result as the index to fetch the drawn number from the other array.