随机 using System; namespace randnumber /**//// <summary> /**//// <summary> RundoubleRandoms(autoRand); /**//// <summary> StringBuilder sb = new StringBuilder(length); for (int i = 0; i < random.Length; i++) } 这其中包含一个用。net中的密码生成创建一个随机的密码串
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Security.Cryptography;
...{
class randnumber
...{
/**//// <summary>
/// 产生随机数的个数
/// </summary>
public int num;
/**//// <summary>
/// 随机数存储的数组
/// </summary>
public double[] randnum;
/// 构造函数
/// </summary>
public randnumber(int num)
...{
this.num = num;
randnum = new double[this.num];
}
/// 产生随机数,填充数组
/// </summary>
/// <returns>产生0--1之间的随机数,填充数组</returns>
private void RundoubleRandoms(Random randObj )
...{
for (int i=0; i < num; i++)
...{
randnum[i] = randObj.NextDouble();
}
}
/**//// <summary>
/// 利用系统时间产生随机数
/// </summary>
/// <remarks>调用RundoubleRandoms方法填充数组</remarks>
public void AutoSeedRandoms()
...{
Random autoRand = new Random();
}
/// 产生一串随机的密码串
/// </summary>
public string GetRandomPassword(int length)
...{
byte[] random = new Byte[length / 2];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(random);
...{
sb.Append(String.Format("{0:X2}", random[i]));
}
return sb.ToString();
}
}
用C#写的随机数产生类
80酷酷网 80kuku.com