
16 Feb
2009
16 Feb
'09
4:24 a.m.
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