利用哈希表生成不重复的随机数时间:2025-04-01 07:09:27函数如下: /// <summary> /// 返回一个记录随机数的Hashtable /// </summary> /// <param name="rmNum">要产生的随机数个数</param> /// <param name="upNum">最大值</param> /// <returns>记录随机数的hashtable</returns> public static Hashtable Random(int rmNum,int upNum) { int nValue = 0; Hashtable hashtable = new Hashtable(); Random rm = new Random(); for (int i = 1; i <= rmNum; i++) { nValue = (upNum); if (!(nValue) && nValue != 0) { (i, nValue); } else { for (int j = 0; ; j++) { nValue = (upNum); if (!(nValue) && nValue != 0) { (i, nValue); break; } else { continue; } } } } return hashtable; }