1个回答
展开全部
public void GenerateRandomNums()
{
List<int> list = new List<int>();
Random rand = new Random();
int value;
while(true)
{
if (list.Count == 20)
{
Console.WriteLine("U should get the 20 random numbers. ");
break;
}
value = rand.Next(1, 21);
if(!list.Contains(value))
{
list.Add(value);
}
}
foreach (int temp in list)
{
Console.WriteLine("Num:{0}.", temp);
}
}
{
List<int> list = new List<int>();
Random rand = new Random();
int value;
while(true)
{
if (list.Count == 20)
{
Console.WriteLine("U should get the 20 random numbers. ");
break;
}
value = rand.Next(1, 21);
if(!list.Contains(value))
{
list.Add(value);
}
}
foreach (int temp in list)
{
Console.WriteLine("Num:{0}.", temp);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询