在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/人工智能/ 為10000個訂單編號,要求訂單號范圍是0到9999,完全隨機,不能有規(guī)律,求思

為10000個訂單編號,要求訂單號范圍是0到9999,完全隨機,不能有規(guī)律,求思路?

thanks

回答
編輯回答
凝雅

創(chuàng)建一個10000大小的數(shù)組,將0-9999以次填入,然后用隨機數(shù)將其打亂

2017年4月12日 06:57
編輯回答
歆久
const arr = [];
for(let i=0;i<10000;i++){
    arr.push(i);
}

function random(arr){
    if(arr.length===0){
        return null;
    }
    const index = Math.floor(Math.random()*arr.length);
    return arr.splice(index, 1)[0];
}

random(arr)就可以獲取到隨機數(shù)

2017年12月20日 00:09