{haskell} 巧用nub生成无重复随机数

无重复版本:

 randomN :: Int -> IO [Int]
 randomN n = do
     gen <- getStdGen
     return $ take n . nub $ randomRs (0, n-1) gen

有重复版本:

 randomN' :: Int -> IO [Int]
 randomN' n = do
     gen <- getStdGen
     return $ take n $ randomRs (0, n-1) gen

你可能感兴趣的:({haskell} 巧用nub生成无重复随机数)