#!r6rs (library (rsc3 random shuffle) (export shuffle) (import (rnrs) (only (rsc3 random range) rand)) ;; Return a random permutation of the `l'. This is not a ;; mutation operation. For a critique of this method see ;; http://okmij.org/ftp/Haskell/perfect-shuffle.txt. (define (shuffle l) (let ((q (map (lambda (e) (cons (rand 0 1) e)) l)) (c (lambda (a b) (> (car a) (car b))))) (map cdr (list-sort q c)))) ;; sclang name for shuffle. (define scramble shuffle) )