JS中實現種子隨機數

參數:dom

詳談JS中實現種子隨機數及做用測試

 

我在Egret裏這麼寫...this

class NumberTool{
    /**種子(任意默認值5)*/ public static seed:number = 5; /**種子隨機數*/ public static seedRandom(){ this.seed = (this.seed * 9301 + 49297) % 233280; return this.seed / 233280.0; }
}

 

其中的 (this.seed * 9301 + 49297) % 233280 這些神祕數字參考「詳談JS中實現種子隨機數及做用」吧,由於我也不知道....net

 

執行種子隨機數htm

//測試
for(let i=0;i<10;i++){
	console.log(NumberTool_Pao.seedRandom());
}

  

第一次輸出:blog

 

 從新運行遊戲,第二次輸出,發現輸出的隨機數都是同樣:遊戲

相關文章
相關標籤/搜索