随机数但不重复
我想生成一个小于 50 的随机数,但一旦生成该数字,我希望它不能再次生成。
谢谢您的帮助!
I would like to generate a random number less than 50, but once that number has been generated I would like it so that it cannot be generated again.
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请参阅:Fisher-Yates 洗牌:
Please see: Fisher–Yates shuffle:
将数字1-49放入可排序集合中,然后按随机顺序排序; 根据需要从集合中弹出每一个。
Put the numbers 1-49 in a sortable collection, then sort it in random order; pop each one out of the collection as needed.
鉴于问题被标记为 VB/VB.Net...这是 Mitch 答案的 VB 实现。
Seeing as the question was tagged VB/VB.Net... this is a VB implementation of Mitch's answer.
下面的代码生成字母数字字符串,其长度作为参数传递。
Below code generate alpha-numeric string with length that you pass as parameter.