[Haskell-beginners] Re: permuting a list
Jon Fairbairn
jon.fairbairn at cl.cam.ac.uk
Sun Feb 15 06:10:28 EST 2009
Heinrich Apfelmus <apfelmus at quantentunnel.de> writes:
> The answer is a resounding "yes" and the main idea is that shuffling a
> list is *essentially the same* as sorting a list; the minor difference
> being that the former chooses a permutation at random while the latter
> chooses a very particular permutation, namely the one that sorts the input.
>
> For the full exposition, see
>
> http://apfelmus.nfshost.com/random-permutations.html
I haven't been following the thread, but my initial reaction
would have been something like use System.Random.randoms to
get a list rs and then do (roughly)
randomPerm = map snd . sortBy (compare `on` fst) . zip rs
How bad is that? I mean, how unfair does it get?
--
Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html (updated 2009-01-31)
More information about the Beginners
mailing list