haskell - How can I generate a random sequence of elements from a list in Haskell?
问题描述
I've had a look through https://hackage.haskell.org/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"
推荐阅读
- laravel-7 - Laravel 中的 ErrorException 未定义变量
- treeview - Treeview 未以 Windows 形式显示 .net 4.8
- javascript - 反应地图数组模式窗口项不起作用
- reactjs - Material-ui.为什么Popover设置Modal的背景不可见
- ios - 如何在没有导航栏标题、项目等的导航栏中创建状态栏背景?
- swiftui - 如何在 swiftui 中添加自定义字体?
- google-sheets - 从 Google 表单中捕获标识符以匹配 E-Blast
- python - Google Calendars API - 不断看到“身份验证流程已完成。您可以关闭此窗口。” 每次我用脚本创建一个事件
- java - javax约束的验证问题
- fonts - python Turtle中的字体类型有问题