随机打印五个数字

//原数组
var arr = [0,1,2,3,4,5,6,7,8,9,10,11];
//输出数组
var out = [];
//输出个数
var num = 5;
while(out.length < num){
    var temp = (Math.random()*arr.length) >> 0;
    out.push(arr.splice(temp,1));
}
alert(out);

 

posted @ 2017-09-11 15:12  松歌  阅读(194)  评论(0编辑  收藏  举报