C#生成随机字符串
1 /// <summary> 2 /// 生成随机字符串 3 /// </summary> 4 private class RandomStringGenerator 5 { 6 static readonly Random r = new Random(); 7 const string _chars = "0123456789"; 8 public static string GetRandomString() 9 { 10 char[] buffer = new char[5]; 11 for (int i = 0; i < 5; i++) 12 { 13 buffer[i] = _chars[r.Next(_chars.Length)]; 14 } 15 return new string(buffer); 16 } 17 }
这个是在StackOverFlow上看见的