1. 程式人生 > >C#生成指定長度隨機數

C#生成指定長度隨機數

urn pub int ++ ret sta 漢字 隨機 col

 1 public static string GetRandomString(int iLength)
 2 {
 3     string buffer = "0123456789";// 隨機字符中也可以為漢字(任何)
 4     StringBuilder sb = new StringBuilder();
 5     Random r = new Random();
 6     int range = buffer.Length;
 7     for (int i = 0; i < iLength; i++)
 8     {
 9         sb.Append(buffer.Substring(r.Next(range),1
)); 10 } 11 return sb.ToString(); 12 }

借鑒原文:https://blog.csdn.net/sds15732622190/article/details/51426527

C#生成指定長度隨機數