View Single Post
  #4 (permalink)  
Old 11-25-2009, 01:51 AM
rdtindsm rdtindsm is offline
Member
 
Join Date: Feb 2009
Posts: 92
Rep Power: 0
rdtindsm is on a distinguished road
Default
OP explicitly does not want "new concepts", i.e. collections, lists, etc.

If you want to keep the code at a more basic level an effective short routine to shuffle is:
[code]
for (i = 0:51){
swap card[i] with card[random]
end for
}[/ code]

only one pass, don't have to check to see if card is pick more than once. You don't really care. Because every slot is visited, every card is guaranteed to be moved, either as a source or destination in a swap. It is allowable to shuffle a card back to the same slot. In place, so memory usage is strictly n

Also suggest just using the numbers 0-51 as cards, then converting using suit = n/13, rank = n % 13; I realize that the purpose of the exercise may be to learn the techniques you are using. That's great.

Last edited by rdtindsm; 11-25-2009 at 02:05 AM.
Reply With Quote