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