Created
December 2, 2013 22:44
-
-
Save christian-marie/7760452 to your computer and use it in GitHub Desktop.
Shuffle a list by selection of a random permutation. Not particularly efficient but easy and readable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
import System.Random | |
shuffle :: [a] -> IO [a] | |
shuffle ss = do | |
i <- getStdRandom $ randomR (0, length ps) | |
return $ ps !! i | |
where ps = permutations ss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment