Skip to main content
1 of 4
ugoren
  • 17.6k
  • 5
  • 54
  • 75

C, 197 chars

d[52],t,s,i; r(){for(t=0,s=1;s<i+2;s*=2)t|=getchar()%2*s;return t>i?r():t;} main(){ for(i=104;i--;)d[i%52]=i<52 ?t=d[s=r()],d[s]=d[i],s=t%13,printf("%c%c\n",s>7?"ATJQK"[s-8]:s+50,"cdhs"[t/13]),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%13=rank, n/14=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