JS中实现种子随机数


参数:

详谈JS中实现种子随机数及作用

 

我在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());
}

  

第一次输出:

 

 重新运行游戏,第二次输出,发现输出的随机数都是一样:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM