如何在 C# 中生成 8 位唯一和随机数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14733752/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:51:57 来源:igfitidea点击:
How to generate 8 digits UNIQUE & RANDOM number in C#
提问by Aruna
Does any body know, how to create unique & random 8 digits number? There are methods to create random numbers, but my requirement is to create an unique also it should be a random number with 8 digits. Any idea?
有谁知道,如何创建唯一且随机的 8 位数字?有创建随机数的方法,但我的要求是创建一个唯一的,也应该是一个 8 位的随机数。任何的想法?
采纳答案by Som Poddar
Random rnd = new Random();
int myRandomNo= rnd.Next(10000000, 99999999); // creates a 8 digit random no.