/**
 * 伪随机数
 */
export class Random {
  private _seed: number;
  seed: number;

  constructor(seed: number = Math.floor(Math.random() * 10000)) {
    this.seed = this._seed = seed;
  }

  reset() {
    this.seed = this._seed;
  }

  random() {
    var x = Math.sin(this.seed) * 10000;
    this.seed += 1;
    return x - Math.floor(x);
  }

  nextBool() {
    return this.random() > 0.5;
  }

  nextInt(n: number) {
    return Math.floor(this.random() * n);
  }
}
