Random random=new Random();//伪随机
1 public class RandomHelper 2 { 3 /// <summary> 4 /// 获取随机数 5 /// </summary> 6 /// <param name="min">包含,能出现的最小值</param> 7 /// <param name="max">包含,能出现的最大值</param> 8 /// <returns></returns> 9 public static int GetRandomNumber(int min, int max) 10 { 11 Guid guid = Guid.NewGuid(); 12 string sGuid = guid.ToString(); 13 int seed = DateTime.Now.Millisecond; 14 for (int i = 0; i < sGuid.Length; i++) 15 { 16 switch (sGuid[i]) 17 { 18 case 'a': 19 case 'b': 20 case 'c': 21 case 'd': 22 case 'e': 23 case 'f': 24 case 'g': 25 seed = seed + 1; 26 break; 27 case 'h': 28 case 'i': 29 case 'j': 30 case 'k': 31 case 'l': 32 case 'm': 33 case 'n': 34 seed = seed + 2; 35 break; 36 case 'o': 37 case 'p': 38 case 'q': 39 case 'r': 40 case 's': 41 case 't': 42 seed = seed + 3; 43 break; 44 case 'u': 45 case 'v': 46 case 'w': 47 case 'x': 48 case 'y': 49 case 'z': 50 seed = seed + 4; 51 break; 52 default: 53 seed = seed + 4; 54 break; 55 } 56 } 57 Random random = new Random(seed); 58 return random.Next(min, max); 59 } 60 }