[plt-scheme] Scheme implementation of Fisher-Yates shuffle
On Aug 9, Phil Bewig wrote:
>
> If you want, you can always do Perl's omigod Schwartzian transform:
>
> (define (shuffle xs)
> (map cdr
> (sort (lambda (x y) (< (car x) (car y)))
> (map (lambda (x) (cons (random 1.0) x)) xs))))
* In PLT, this is a one-liner:
(sort xs < #:key (lambda (_) (random)) #:cache-keys? #t)
* I think that many Lispers (and therefore Schemers) inlcuding myself
view the "Schwartzian transform" term as a borderline insult. It
has been in use for decades, well before Perl existed.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://barzilay.org/ Maze is Life!