1. Originally Posted by wolly
Ok,but how is that suppose to help me if I want to pick 6 numbers and not 49?
The idea is that if you have a list of 49 numbers, to select the first 6 numbers at random without replacement, you do a partial shuffle such that the first 6 numbers out of the 49 are done with the shuffling (or you can completely shuffle all 49, that's fine too, just extra work). Then, you just need to select these first 6 numbers, ignoring the remaining 43, and you're done. Doing this right is slightly tricky though: Salem's post #44 demonstrates a somewhat different shuffling approach that arguably does too much and yet risks doing too little: you need to shuffle the entire list, and yet if you don't have enough iterations, you won't be shuffling enough.

A correct and efficient approach is as given in the Knuth/Fisher-Yates shuffle: you repeatedly randomly select an item from the "unshuffled" portion of the list and swap it into position; the item that was swapped out of position now forms part of the "unshuffled" portion of the list, whereas the item that was swapped into position joins the "shuffled" portion of the list. This is basically akin to having a bag of items and taking them one by one at random to join your sequential hand of items. Therefore, you can do a partial shuffle with just 6 iterations with one swap each and you're done, needing only 6 random numbers to be generated.

You might find it easier to implement another approach: build your list of random numbers by generating random numbers in the range and checking to see if it already exists if your list of generated numbers. If it doesn't, you add it to the list, otherwise you regenerate the random number. This approach works fine here because the number of numbers you want is much smaller than the range.

2. Originally Posted by laserlight
The idea is that if you have a list of 49 numbers, to select the first 6 numbers at random without replacement, you do a partial shuffle such that the first 6 numbers out of the 49 are done with the shuffling ....

A correct and efficient approach is as given in the Knuth/Fisher-Yates shuffle: ...
Incidentally, I mentioned using the Fisher-Yates algorithm in #4 and gave some code in #10 that does basically what you suggested. It seems like wolly either isn't reading or isn't understanding our replies.

3. Originally Posted by wolly
Ok,but how is that suppose to help me if I want to pick 6 numbers and not 49?
Did it cross your mind that when you saw the output of
Code:
```  for(i=0;i<49;i++){
printf("%d,",lotto[i]);
}```
That changing it to
Code:
```  for(i=0;i<6;i++){
printf("%d,",lotto[i]);
}```
would just give you the 6 random numbers from the pool of 49 numbers.