XIN'BOLG

导航

4月6日--js生成随机数列

newarr=[1,2,3,4,5,6]
function randomsort(a,b){
return Math.random()>0.5?-1:1;
}
//用Math.random()函数生成0~1之间的随机数与0.5比较,返回-1或1  
newarr = newarr.sort(randomsort);
console.log(newarr);

posted on 2017-04-06 15:47  XIN'BOLG  阅读(121)  评论(0编辑  收藏  举报