且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在角色中生成5位数

更新时间:2023-02-10 17:53:02

private const int NumberOfRandomInts = 30;

// initialize the Random generator outside any loop !
Random rnd = new Random((int) DateTime.Now.Ticks & 0x0000FFFF);

List<int> rndIntList = new List<int>(NumberOfRandomInts );

while(rndIntList.Count < NumberOfRandomInts )
{
    int i = rnd.Next(10000, 99999);

    if (rndIntList.Contains(i)) continue;

    rndIntList.Add(i);
}</int></int>

现在根据需要将'rndIntList的内容存储在您的数据库中。

Now store the content of 'rndIntList in your Database as required.


查看下面的代码,它将为您提供30个随机的5位数字。



Check out below code, it will give you 30 random 5 digits numbers.

List<int> numbers = new List<int>();

for (; numbers.Count < 30; )
{
    int i = new Random().Next(10000, 99999);
    if (numbers.Contains(i)) continue;

    numbers.Add(i);
}





如果代码中提到了条件,那么这些数字不应包含重复的数字。您可以根据需要更改for循环条件。



if condition is been mentioned in the code, so that numbers should not contain duplicate numbers. You can change the for loop condition depend how many numbers you want.