{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

推荐阅读更多精彩内容