Skip to main content
3 of 4
edited body
ugoren
  • 17.6k
  • 5
  • 54
  • 75

C, 197 177 chars

B[52],t,s,i=104; r(){for(s=0,t=1;t<=i;t*=2)s|=getchar()%2*t;s>i&&r();} main(){ for(;i--;r())B[i%52]=i<52 ?t=B[s],B[s]=B[i],printf("%c%c\n","23456789ATJQK"[t/4],"cdhs"[t%4]),t :i-52; } 

The basic logic is simple - initialize an array of 52 ints with 0..51, shuffle (randomally replace element x with another from the range 0..x), print formatted (n/4=rank, n%4=suit).
One loop, that runs 104 times, does initialization (first 52 runs), shuffling and printing (last 52 runs).
A random number is generated by pulling n random bits, until 1<<n is at least the desired maximum. If the result is more than the maximum - retry.

ugoren
  • 17.6k
  • 5
  • 54
  • 75