summaryrefslogtreecommitdiff
path: root/21-28/25.hs
blob: 4306ae19f33151ff89a20c2c095e3e1ba2488601 (plain) (blame)
1
2
3
4
5
6
7
8
9
import System.Random
rndPermu :: [a] -> IO [a]

rndPermu l = d l (length l)
    where
        d l@(x:xs) n | n > 0 = do i <- getStdRandom $ randomR (0, (length l) - 1)
                                  r <- d (take i l ++ drop (i + 1) l) (n - 1)
                                  return (l!!i:r)
        d _ _ = return []