
I was looking for a shuffling algorithm to shuffle mp3-playlists so was very happy to see System.Random.Shuffle: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/random-shuffle-0.... However I get errors,non-exhaustive patterns in function shufleTree or extractTree depending how I call it. Errors are at the bottom. I fixed it but I don't have the math skills to see if I perhaps broke it statistically ... Here is my fix, someone (don't remember who, helped me a little): http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2789#a2789 the shuffle at the end is with the fix. *Freet> S.shuffle [1..10] [1..3] Loading package syb ... linking ... done. Loading package base-3.0.3.0 ... linking ... done. Loading package old-locale-1.0.0.1 ... linking ... done. Loading package old-time-1.0.0.1 ... linking ... done. Loading package random-1.0.0.1 ... linking ... done. Loading package random-shuffle-0.0.2 ... linking ... done. [2,4,6*** Exception: src\System\Random\Shuffle.hs:(52,6)-(55,30): Non-exhaustive patterns in function shuffleTree *Freet> S.shuffle [1..3] [1..10] [2,*** Exception: src\System\Random\Shuffle.hs:(66,6)-(79,27): Non-exhaustive patterns in function extractTree *Freet> :load "c:/ghc/ghc-6.10.1/progs/Mp3Player/Shuffle.hs" [1 of 1] Compiling Shuffle ( C:\ghc\ghc-6.10.1\progs\Mp3Player\Shuffle.hs, interpreted ) Ok, modules loaded: Shuffle. *Shuffle> shuffle [1..3] [1..10] [2,1,3] *Shuffle> shuffle [1..10] [1..3] [2,4,6*** Exception: C:\ghc\ghc-6.10.1\progs\Mp3Player\Shuffle.hs:(27,13)-(31,30): Non-exhaustive patterns in function shuffle' *Shuffle> shuffle [1..10] [1..10] [2,4,6,8,10,3,9,7,5,1] *Shuffle>

friggin friggin ha scritto:
I was looking for a shuffling algorithm to shuffle mp3-playlists so was very happy to see System.Random.Shuffle: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/random-shuffle-0....
However I get errors,non-exhaustive patterns in function shufleTree or extractTree depending how I call it. Errors are at the bottom.
During building you should only get warnings. Non exhaustive patterns are ok, you hit them only if the input data is incorret. Probably in these cases, error should be used.
I fixed it but I don't have the math skills to see if I perhaps broke it statistically ...
Here is my fix, someone (don't remember who, helped me a little): http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2789#a2789 the shuffle at the end is with the fix.
*Freet> S.shuffle [1..10] [1..3]
Your input is not correct. If you read the source code (in a future version I'll add Haddock support): -- Given a sequence (e1,...en) to shuffle, and a sequence -- (r1,...r[n-1]) of numbers such that r[i] is an independent sample -- from a uniform random distribution [0..n-i], compute the -- corresponding permutation of the input sequence. I have added a convenience function `shuffle'`, where you just need to supply a random number generator. Note that the shuffle' function contains a "bug"; it should return the new random generator: shuffle' :: RandomGen gen => [a] -> Int -> gen -> ([a], gen) I'm going to fix it in next version.
[...]
Regards Manlio
participants (2)
-
friggin friggin
-
Manlio Perillo