class Program { static void Main() { System.Random r = new System.Random(); int[] a = new int[]{0,1,2,3,4,5,6,7,8,9}; for (int i = a.Length; i > 1; i--) { int j = r.Next(i); int t = a[i - 1]; a[i - 1] = a[j]; a[j] = t; }
// 输出结果 foreach (int x in a) System.Console.WriteLine(x); } }
Sub Main() Dim List As New List(Of Integer) For i As Integer = 0 To 9 List.Add(i) Next Dim Count As Integer = 0 Dim Rnd As New Random Dim Index As Integer = 0 For k As Integer = 0 To 9 Count = List.Count - 1 Index = Rnd.Next(0, Count) Console.WriteLine(List(Index)) List.RemoveAt(Index) Next Console.Read() End Sub
{
static void Main()
{
System.Random r = new System.Random();
int[] a = new int[]{0,1,2,3,4,5,6,7,8,9};
for (int i = a.Length; i > 1; i--)
{
int j = r.Next(i);
int t = a[i - 1];
a[i - 1] = a[j];
a[j] = t;
}
// 输出结果
foreach (int x in a) System.Console.WriteLine(x);
}
}
For i As Integer = 0 To 9
List.Add(i)
Next Dim Count As Integer = 0
Dim Rnd As New Random
Dim Index As Integer = 0
For k As Integer = 0 To 9 Count = List.Count - 1
Index = Rnd.Next(0, Count)
Console.WriteLine(List(Index))
List.RemoveAt(Index) Next Console.Read() End Sub
- - 给了思路,没给代码就不给分..给LZ一点思考的余地嘛LZ太不厚道了...下次,我也要把代码写出来啦. 每天10分 哦也.