参数:
我在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());
}
第一次输出:

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