public static string GenerateRandomNumber(int Length) { System.Text.StringBuilder newRandom = new System.Text.StringBuilder(10); Random rd = new Random(); for (int i = 0; i < Length; i++) { newRandom.Append(constant[rd.Next(10)]); } return newRandom.ToString(); }
------解决方案--------------------
guid.newguid Random rand = new Random(Guid.NewGuid().GetHashCode());
------解决方案--------------------
------解决方案-------------------- List history = new List();
Random rd = new Random(); int num = rd.Next(100000000); 数字直接生成就可以,0-9,刚好是10进制8位还在int32范围之内 while (history.Contains(num)) num = rd.Next(100000000); //重复就再来一次 history.Add(num);
------解决方案-------------------- 一个GUID解决所有问题!!!!
------解决方案--------------------
C# code
Random b = new Random();
int length =10;
int rand=b.Next(100000000);
int[] No = new int[length];//
bool[] a = new bool[100000000];
for (int i = 0; i < length; i++)
{
if (!a[rand])
{
No[i] = rand;
}
else
{
i--;
}
rand = b.Next(100000000);
}
------解决方案--------------------
Random b = new Random();
int length =10;
int rand=b.Next(100000000);
int[] No = new int[length];//
bool[] a = new bool[100000000];
for (int i = 0; i < length; i++)
{
if (!a[rand])
{
No[i] = rand;
a[rand]=true; //漏了!
}
else
{
i--;
}
rand = b.Next(100000000);
}
------解决方案--------------------