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中的密碼生成創建一個隨機的密碼串