c# 不重复的随机数
1 Hashtable hashtable = new Hashtable(); 2 Random rm = new Random(); 3 int RmNum = 5; //随机数个数 4 for (int i = 0; hashtable.Count < RmNum; i++) 5 { 6 int nValue = rm.Next(-5,5);//随机数范围 7 if (!hashtable.ContainsValue(nValue) && nValue != 0) 8 { 9 hashtable.Add(nValue, nValue); 10 Console.WriteLine(nValue.ToString()); 11 } 12 }