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

 

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

相关文章
相关标签/搜索