Skip to content

Instantly share code, notes, and snippets.

@christian-marie
Created December 2, 2013 22:44
Show Gist options
  • Save christian-marie/7760452 to your computer and use it in GitHub Desktop.
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.
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