Random 生成不重复的随机数


Hashtable ha = new Hashtable();
Random rm = new Random();

for (int i = 0; ha.Count < 4; i++)
{
  int number = rm.Next(1,10);
if (!ha.ContainsValue(number))
{
  ha.Add(number, number);

  Console.WriteLine(number.ToString());
}
}

posted @ 2017-05-27 14:36  青年a  阅读(2472)  评论(0编辑  收藏  举报