
Hello! =) I wonder why Oleg's perfect shuffle[1] isn't on any standard library? Is there a reason or is it just a lack of patches? I'd personally like to have at least the function
shuffle :: RandomGen g => g -> [a] -> [a] shuffle gen list = let len = length list ran = [r `mod` k | (k,r) <- zip [len,len-1..2] randoms gen] in shuffle1 cartas rs'
where shuffle1 is Oleg's perfect shuffle and length is the beSureYouReallyWantIntBeforeUsingThisLength ;). Cheers, [1] http://okmij.org/ftp/Haskell/perfect-shuffle.txt -- Felipe.

Felipe Almeida Lessa
I wonder why Oleg's perfect shuffle[1] isn't on any standard library?
This is incorrect terminology: A perfect shuffle is one where the cards interleave in a 1:1:1:1:1... pattern, achieving exactly the same permutation of the deck each time. For example, a perfect shuffle of 52 cards where the top and bottom cards stay fixed has order 8: Do one eight times and the deck will return to its original ordering. Most people are incapable of executing a perfect shuffle, but various magicians have mastered this as sleight of hand. I am one of the authors of Dave Bayer, Persi Diaconis Trailing the dovetail shuffle to its lair Ann. Appl. Probab. 2 (1992), no. 2, 294-313 which found a closed form formula for the probabilities involved in riffle shuffles, how people shuffle e.g. playing bridge. This work was summarized as "seven shuffles suffice". I once watched my coauthor, Persi, perform a card trick as part of a talk, where he threw in a shuffle just to amuse himself before starting the trick. It happened to be a perfect shuffle, or the trick would have failed. I chortled eight hours later in a solemn moment in a modern dance concert, it took me this long to realize he had done this. What Oleg means is that his code achieves a uniform distribution after one pass.

Felipe Almeida Lessa wrote:
I'd personally like to have at least the function
shuffle :: RandomGen g => g -> [a] -> [a]
Me too (along with permutations and a few, perhaps. shuffle doesn't create very long lists it doesn't start with, though, which makes me feel good about this...) shuffle is tricky to implement correctly, so its absence usually causes trouble (when it is needed), so it is worth including, IMO. Where should it be put? System.Random already doesn't make sense to me (why System?); Random. ? Statistics. ?? Isaac
participants (3)
-
Dave Bayer
-
Felipe Almeida Lessa
-
Isaac Dupree