參數:
我在Egret里這么寫...
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中實現種子隨機數及作用”吧,因為我也不知道...
執行種子隨機數
//測試 for(let i=0;i<10;i++){ console.log(NumberTool_Pao.seedRandom()); }
第一次輸出:
重新運行游戲,第二次輸出,發現輸出的隨機數都是一樣: