Page Top

C#生成指定长度随机数

 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

posted @ 2018-08-03 15:09  抹茶大虾球丶  阅读(1088)  评论(0编辑  收藏  举报