110,534
社区成员
发帖
与我相关
我的任务
分享
List<Int32> list = new List<Int32>();
while(true)
{
Random r = new Random();
int n = r.Next(1,70);
if(!list.Contains(n))
{
list.Add(n);
}
if (list.Count > 20)
{
break;
}
}
//这个是输出20个1-70的不重复的数啊,没有重复的。。。
using System;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Collections.Generic;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
int Count = 0;
List<int> r = new List<int>();
List<int> Result = new List<int>();
int MaxCount = 50;
while (true)
{
int i = new Random().Next(1, 1000);
if (!r.Contains(i))
{
r.Add(i);
Count++;
}
if (Count >= MaxCount) break;
}
Result.AddRange(r.OrderBy(i => i));
Console.ReadKey();
}
}
}
static Random r = new Random();