随机数生成器的组合
给定两个随机整数生成器,一个生成 1 到 7 之间的值,另一个生成 1 到 5 之间的值,如何制作一个生成 1 到 13 之间的随机整数生成器?我尝试过以各种方式解决这个问题,但我一直无法想出一个以相等或接近相等的概率生成从 1 到 13 的数字的解决方案。
Given two random integer generators one that generates between 1 and 7 and another that generates between 1 and 5, how do you make a random integer generator that generates between 1 and 13? I have tried solving this question in various ways but I have not been able to come up with a solution that generates numbers from 1 to 13 with equal or near equal probability.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用将随机范围从 1–5 扩展到 1–7 的前两个答案,我得出了以下结论。可能有一种更有效的方法来做到这一点(也许使用 1-5 生成器?)但这似乎可行。
针对紧凑性进行了优化
针对可理解性进行了优化
Using the top two answers for Expand a random range from 1–5 to 1–7, I've come up with the following. There's probably a more efficient way to do this (maybe using the 1-5 generator?) but this seems to work.
Optimized for Compactness
Optimized for understandability