本文介绍了如何从Haskell的列表中生成元素的随机序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我浏览了 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"更多推荐
如何从Haskell的列表中生成元素的随机序列?
发布评论