tryusing System;class TestOrder
{
  static void Main()
  {
int[] its = new int[30];
for (int i=0; i < its.Length; i++)
its[i] = i; System.Random r = new System.Random();
for (int i=its.Length-1; i >= 0; i--)
{
int islot = r.Next(i+1);
int temp = its[islot];
its[islot] = its[i];
its[i] = temp;
}
for (int i=0; i < its.Length; i++)
Console.WriteLine("{0}:\t{1}",i,its[i]);
  }
}

解决方案 »

  1.   

    have you tried the code? do you understand the code? look at the output from its[i], not i:
    0:      27
    1:      19
    2:      5
    3:      20
    4:      2
    5:      25
    6:      10
    7:      16
    8:      23
    9:      29
    10:     24
    11:     12
    12:     28
    13:     8
    14:     1
    15:     6
    16:     21
    17:     22
    18:     18
    19:     11
    20:     15
    21:     4
    22:     26
    23:     3
    24:     14
    25:     17
    26:     7
    27:     0
    28:     13
    29:     9