生成一个4位数字 [英] Generate a 4 digit number
本文介绍了生成一个4位数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何生成从0000到4999的4位数字。
这是我到目前为止所尝试的
Random rnd = new Random();
rnd.Next( 0000 , 4999 );
int id = rnd;
我可以使用(1,9)四次但不是还有另外一种方法吗?
解决方案
试试这个:
随机rnd = new Random();
int myRandomNo = rnd.Next(1000,9999);
Random rnd = new Random();
int id = rnd.Next( 0 , 4 )+ rnd.Next( 0 , 9 )+ rnd.Next(< span class =code-digit> 0 , 9 )+ rnd.Next( 0 , 9 );
How go I generate a 4 digit number starting from 0000 to 4999.
This is what I've tried so far
Random rnd = new Random();
rnd.Next(0000, 4999);
int id = rnd;
I can use (1, 9) four times but isn't there another way?
解决方案
Try this:
Random rnd = new Random(); int myRandomNo = rnd.Next(1000, 9999);
Random rnd = new Random(); int id = rnd.Next(0, 4) + rnd.Next(0, 9) + rnd.Next(0,9) + rnd.Next(0, 9);
这篇关于生成一个4位数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文