62,046
社区成员
发帖
与我相关
我的任务
分享
public string getRandom(int length)
{
Dictionary<double, object> test = new Dictionary<double, object>();
int DoubleCount = 0;
for (int bi1 = 0; bi1 < length; bi1++)
{
Guid temp = Guid.NewGuid();
double Return = BitConverter.ToDouble(temp.ToByteArray(), 0);
if (test.ContainsKey(Return))
{
DoubleCount++;
}
else
{
test.Add(Return, null);
}
}
return DoubleCount.ToString();
}
//数字+大写字母
public string getRandom(int length)
{
byte[] random = new Byte[length / 2];
// 使用加密服务提供程序 (CSP) 提供的实现来实现加密随机数生成器 (RNG)。无法继承此类
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(random);
StringBuilder sb = new StringBuilder(length);
int i;
for (i = 0; i < random.Length; i++)
{
// 以16进制格式输出
sb.Append(String.Format("{0:X2}", random[i]));
}
return sb.ToString();
}
string[] result = new string[5000];
Random r = new Random();
StringBuilder sb;
int n;
for (int i = 0; i < result.Length; i++)
{
sb = new StringBuilder();
for (int j = 0; j < 8; j++)
{
n = r.Next(62);
if (n < 10)
sb.Append(n);
else
if (n < 36)
sb.Append((char)(n + 55));
else
sb.Append((char)(n + 61));
}
result[i] = sb.ToString();
}
for (int i = 0; i < result.Length; i++)
Response.Write(result[i] + "<br/>");
string[] result = new string[5000];
Random r = new Random();
StringBuilder sb;
for (int i = 0; i < result.Length; i++)
{
sb = new StringBuilder();
for (int j = 0; j < 8; j++)
sb.Append(r.Next(10));
result[i] = sb.ToString();
}
for (int i = 0; i < result.Length; i++)
Response.Write(result[i] + "<br/>");