110,534
社区成员
发帖
与我相关
我的任务
分享
int[] nums = new int[27];
for(int i=0; i<nums.Length; i++) nums[i] = 20 + i;
Random rand = new Random();
for(int i=nums.Length-1; i > 0; i--)
{
// randomly choose a position to pop out, j belongs to [0,i-1]
int j = rand.Next( i );
// swap the popped-out to the rear the array
int tmp = nums[i];
nums[i] = nums[j];
nums[j] = tmp;
}
Random rand = new Random();
var randomSeq = Enumerable.Repeat(0,20).Select(i => rand.Next(20,46));
Random r = new Random();
List<int> list = new List<int>();
while(list.Count<28)
{
int i = r.Next(20,46);
if(!list.Contains(i))
list.Add(i);
}
static void Main(string[] args)
{
int[] a = new int[] { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46 };
Random r = new Random();
for (int i = a.Length - 1; i > 6;i-- )
{
int temp = r.Next(0, i);
int delete = a[temp];
a[temp] = a[i];
a[i] = delete;
}
for (int i = 0; i < 20; i++)
Console.WriteLine(a[i]);
Console.Read();
}
static void Main(string[] args)
{
int[] a = new int[] { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46 };
Random r = new Random();
for (int i = a.Length - 1,j=0; i > 6;i--,j++ )
{
int temp = r.Next(0, i);
int delete = a[temp];
a[temp] = a[i];
a[i] = delete;
}
for (int i = 0; i < 20; i++)
Console.WriteLine(a[i]);
Console.Read();
}
int [] a ={20,21,22,23,24,25,26,27,28,29,30};
List<int> tmp = new List<int>(a);
List<int> result = new List<int>();
Random r = new Random();
for (int i = tmp.Count-1; i >= 0; i--)
{
int j= r.Next(tmp.Count);
result.Add(tmp[j]);
tmp.RemoveAt(j);
}