我浏览了 hackage.haskell/package/random-1.1/docs/System-Random.html ,但是我看不到如何使用自定义列表",例如 ['a'..'z'] ++ ['0'..'9'] ?
I've had a look through hackage.haskell/package/random-1.1/docs/System-Random.html however I can't see how to use a custom "list" for example an alphanumeric list of ['a'..'z'] ++ ['0' .. '9']?
我想作为一种解决方法,我可以改为映射一组随机数字.
I suppose as a workaround I could instead map a random set of numbers instead.
推荐答案我提到的实现工作的实现:
The implementation of the work around I mentioned:
Prelude> import System.Random Prelude System.Random> gen <- newStdGen Prelude System.Random> x = ['a'..'z'] ++ ['0' .. '9'] Prelude System.Random> fmap (x !! ) (take 10 $ randomRs (0, length x - 1 ) gen) "h4tm52rfox"