Heinrich Apfelmus wrote:
Alberto Ruiz wrote:
How about using random doubles?

randomPerm xs = fmap (map snd . sort . flip zip xs) rs
    where rs = fmap (randoms . mkStdGen) randomIO :: IO [Double]

Interesting idea. The chance of duplicates should be negligible now, but
that's because we're using a large amount of random bits, far more than
n! would require.

Another possibility is using infinite lists of random bits as keys. Then we only extract from the random number generator the number of bits required to avoid duplicates.

-Alberto
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to