c#写程序,怎样产生1-33中6个不重复的数

如题所述

static void Main(string[] args)
{
List<int> list = new List<int>();
Random rd=new Random();
while (list.Count < 6) //产生1-33中6个不重复的数
{
int num= rd.Next(1, 34);
if (!list.Contains(num))
list.Add(num);

}

foreach (int num in list)
{
Console.WriteLine(num); //将得到的6个数打印
}
Console.ReadKey();

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-09-12
用随机函数
具体参照
http://www.cnblogs.com/wang726zq/archive/2012/04/28/2474711.html
希望对你有帮助
相似回答