* @zh 创建种子随机数生成器 * @en Create seeded random number generator * * @param seed - @zh 随机种子 @en Random seed
(seed: number = Date.now())
| 23 | * @param seed - @zh 随机种子 @en Random seed |
| 24 | */ |
| 25 | constructor(seed: number = Date.now()) { |
| 26 | // Initialize with MurmurHash3 mixing |
| 27 | let h = seed | 0; |
| 28 | h = Math.imul(h ^ (h >>> 16), 0x85ebca6b); |
| 29 | h = Math.imul(h ^ (h >>> 13), 0xc2b2ae35); |
| 30 | h ^= h >>> 16; |
| 31 | |
| 32 | this._s0 = h >>> 0; |
| 33 | this._s1 = (h * 0x9e3779b9) >>> 0; |
| 34 | |
| 35 | // Ensure non-zero state |
| 36 | if (this._s0 === 0) this._s0 = 1; |
| 37 | if (this._s1 === 0) this._s1 = 1; |
| 38 | |
| 39 | this._initialS0 = this._s0; |
| 40 | this._initialS1 = this._s1; |
| 41 | |
| 42 | // Warm up |
| 43 | for (let i = 0; i < 10; i++) { |
| 44 | this.next(); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @zh 重置到初始状态 |