生成不重复随机数的疑问(C#)?
protected void Button1_Click(object sender, EventArgs e) { s="17,18,19,20"; //输出随机生成的红号和蓝号列表 string[] ss = s.Split(','); for (int x = 0; x < ss.Length; x++) { Response.Write("红号" + getRedCode() + "蓝号" + ss[x].ToString()+"<br>"); } } public string getRedCode() { string str = ""; Hashtable hashtable = new Hashtable(); Random rm = new Random(); int RmNum = 6; for (int i = 0; hashtable.Count < RmNum; i++) { int nValue = rm.Next(34); if (!hashtable.ContainsValue(nValue) && nValue != 0) { hashtable.Add(nValue, nValue); str+=nValue.ToString()+","; } } return str.Remove(str.Length - 1); }