110,571
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
namespace Random
{
class Program
{
static void Main(string[] args)
{
RandomList randomList = new RandomList(8);
List<int> tt = randomList.Random();
foreach (int k in tt)
{
Console.WriteLine(k);
}
Console.ReadLine();
}
}
class RandomList
{
private List<int> _list;
private int _maxInt;
public RandomList(int maxInt)
{
_maxInt=maxInt;
_list = new List<int>(maxInt);
for (int i = 1; i <= maxInt;i++ )
{
_list.Add(i);
}
}
public List<int> Random()
{
List<int> tempList = new List<int>(_maxInt);
int temp;
for (int i = _maxInt; i > 0;i-- )
{
System.Random random = new System.Random();
temp = random.Next(0, i-1);
tempList.Add(_list[temp]);
_list.RemoveAt(temp);
}
return tempList;
}
}
}