AS打乱数组方法

技术的提高就是在工作中进行的,我深信这一点.今天就在就遇到数组乱排的问题.其实解决问题的方法很多.下面的方法只是简单打乱.
[as] // Here is a simple function for randomizing the array function randomsort(a, b) { return Math.random()>.5 ? -1 : 1; } //usage example var arr = [1, 2, 3, 4, 5]; arr.sort(randomsort); trace(arr); //traces 4,3,1,5,2 [/as]
如果谁有更好的方式希望可以共享下.

posted on 2012-07-18 20:38  AS3.0  阅读(260)  评论(0编辑  收藏  举报

导航