As如下:
paigu_array = new Array();
num_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
N = num_array.length;
for (i=0; i<N; i++) {
Num = N-i;
a = random(Num);
paigu_array[i] = num_array[a];
num_array.splice(a, 1);
//trace(num_array.join(" ;"));
}
trace(":"+paigu_array.join(" "));
num_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
N = num_array.length;
for (i=0; i<N; i++) {
Num = N-i;
a = random(Num);
paigu_array[i] = num_array[a];
num_array.splice(a, 1);
//trace(num_array.join(" ;"));
}
trace(":"+paigu_array.join(" "));
输出结果如下:
:3 8 10 5 4 9 2 1 7 6
:2 7 6 5 1 10 9 4 8 3
:3 7 8 4 9 5 6 1 2 10
:8 6 3 4 7 10 2 9 5 1
:9 4 8 3 6 10 2 7 5 1
:5 7 2 4 6 8 1 3 10 9
:2 7 6 5 1 10 9 4 8 3
:3 7 8 4 9 5 6 1 2 10
:8 6 3 4 7 10 2 9 5 1
:9 4 8 3 6 10 2 7 5 1
:5 7 2 4 6 8 1 3 10 9
可以用在课件中
比如说有十道题目
我们只想随机抽取其中三道来提问
就可以用到这样的[随机排列自然数]
数组真是个好东西啊
看来以后要多用用