using system;
using system.collections.generic;
using system.text;
using system.threading;
using system.security.cryptography;
namespace randnumber
...{
class randnumber
...{
/**//// <summary>
/// 产生随机数的个数
/// </summary>
public int num;
/**//// <summary>
/// 随机数存储的数组
/// </summary>
public double[] randnum;
/**//// <summary>
/// 构造函数
/// </summary>
public randnumber(int num)
...{
this.num = num;
randnum = new double[this.num];
}
/**//// <summary>
/// 产生随机数,填充数组
/// </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();
rundoublerandoms(autorand);
}
/**//// <summary>
/// 产生一串随机的密码串
/// </summary>
public string getrandompassword(int length)
...{
byte[] random = new byte[length / 2];
rngcryptoserviceprovider rng = new rngcryptoserviceprovider();
rng.getnonzerobytes(random);
stringbuilder sb = new stringbuilder(length);
for (int i = 0; i < random.length; i++)
...{
sb.append(string.format("{0:x2}", random[i]));
}
return sb.tostring();
}
}
}
这其中包含一个用。net中的密码生成创建一个随机的密码串
新闻热点
疑难解答