C#生成不重复的N位随机数
直接上代码:
#region 生成N位随机数 /// <summary> /// 生成N位随机数 /// </summary> /// <param name="N">N位随机数</param> /// <returns>生成的N位随机数</returns> public static string RandCode(int N) { char[] arrChar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; StringBuilder num = new StringBuilder(); Random rnd = new Random(Guid.NewGuid().GetHashCode()); for (int i = 0; i < N; i++) { num.Append(arrChar[rnd.Next(0, arrChar.Length)].ToString()); } return num.ToString(); } #endregion
(本人微信号:Liberty-bcy)如果,你正在埋怨命运不眷顾,那请记住:命,是失败者的借口;运,是成功者的谦词。