[Haskell-cafe] Re: permuting a list

2009-02-18 Thread Henning Thielemann
On Tue, 17 Feb 2009, Okasaki, C. DR EECS wrote: The discussion of randomly permuting a list comes up every few years.  Here’s what I wrote last time (2005): ... How about putting it on the Wiki?___ Haskell-Cafe mailing list

[Haskell-cafe] Re: permuting a list

2009-02-17 Thread Okasaki, C. DR EECS
The discussion of randomly permuting a list comes up every few years. Here's what I wrote last time (2005): Clearly, you can do a perfect shuffle in O(N) time using mutable arrays, using the standard imperative algorithm. You can also do it in O(N) expected time using *immutable* arrays, using

Re: [Haskell-beginners] Re: [Haskell-cafe] Re: permuting a list

2009-02-16 Thread Alberto Ruiz
Heinrich Apfelmus wrote: Alberto Ruiz wrote: How about using random doubles? randomPerm xs = fmap (map snd . sort . flip zip xs) rs where rs = fmap (randoms . mkStdGen) randomIO :: IO [Double] Interesting idea. The chance of duplicates should be negligible now, but that's because we're

[Haskell-cafe] Re: permuting a list

2009-02-16 Thread Jon Fairbairn
Paul Johnson p...@cogito.org.uk writes: See http://okmij.org/ftp/Haskell/perfect-shuffle.txt I should have read that first time round! -- Jón Fairbairn jon.fairba...@cl.cam.ac.uk http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html (updated 2009-01-31)

[Haskell-cafe] Re: permuting a list

2009-02-15 Thread Jon Fairbairn
Heinrich Apfelmus apfel...@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

[Haskell-cafe] Re: permuting a list

2009-02-15 Thread Heinrich Apfelmus
Jon Fairbairn wrote: Heinrich Apfelmus 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

Re: [Haskell-cafe] Re: permuting a list

2009-02-15 Thread Alberto Ruiz
Heinrich Apfelmus wrote: Jon Fairbairn wrote: Heinrich Apfelmus 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

Re: [Haskell-cafe] Re: permuting a list

2009-02-15 Thread Felipe Lessa
On Sun, Feb 15, 2009 at 9:47 AM, Heinrich Apfelmus apfel...@quantentunnel.de wrote: It's fair, but may duplicate elements, i.e. it doesn't necessarily create a permutation. For example, rs could be something like rs = [5,3,3,3,2,4] But our sort doesn't discard values when the keys are

[Haskell-cafe] Re: permuting a list

2009-02-15 Thread Heinrich Apfelmus
Felipe Lessa wrote: Heinrich Apfelmus wrote: It's fair, but may duplicate elements, i.e. it doesn't necessarily create a permutation. For example, rs could be something like rs = [5,3,3,3,2,4] But our sort doesn't discard values when the keys are the same. For example, [1,2,3,4]

Re: [Haskell-cafe] Re: permuting a list

2009-02-15 Thread Paul Johnson
See http://okmij.org/ftp/Haskell/perfect-shuffle.txt Paul. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

[Haskell-cafe] Re: permuting a list

2009-02-14 Thread Henning Thielemann
On Sat, 14 Feb 2009, Daniel Fischer wrote: Am Samstag, 14. Februar 2009 16:37 schrieb Heinrich Apfelmus: For the full exposition, see http://apfelmus.nfshost.com/random-permutations.html Excellent work, thanks. Interesting read. Btw. a further development of the PFP library is also