previous | index | next

General Purpose Shuffling

To shuffle a deck of any size:
     (define shuffle
       (lambda (deck size)
         (let ((half (quotient (+ size 1) 2)))
           (interleave (first-elements-of half deck)
                       (list-tail deck half)))))
half is chosen in this way so that if the size is odd, the first half will have the extra card.

previous | index | next