blob: 4306ae19f33151ff89a20c2c095e3e1ba2488601 (
plain) (
tree)
|
|
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 []
|