import { s as h } from "./index-CieiGp4Y.js";
class u {
  constructor(t, e, a, s, i) {
    this.mean = t, this.stdDev = e, this.dtype = a, this.nextVal = NaN, this.truncated = s, this.truncated && (this.upper = this.mean + this.stdDev * 2, this.lower = this.mean - this.stdDev * 2);
    const n = i || Math.random();
    this.random = h.alea(n.toString());
  }
  /** Returns next sample from a Gaussian distribution. */
  nextValue() {
    if (!isNaN(this.nextVal)) {
      const s = this.nextVal;
      return this.nextVal = NaN, s;
    }
    let t, e, a = !1;
    for (; !a; ) {
      let s, i, n;
      do
        s = 2 * this.random() - 1, i = 2 * this.random() - 1, n = s * s + i * i;
      while (n >= 1 || n === 0);
      const r = Math.sqrt(-2 * Math.log(n) / n);
      t = this.mean + this.stdDev * s * r, e = this.mean + this.stdDev * i * r, (!this.truncated || this.isValidTruncated(t)) && (a = !0);
    }
    return (!this.truncated || this.isValidTruncated(e)) && (this.nextVal = this.convertValue(e)), this.convertValue(t);
  }
  /** Handles proper rounding for non-floating-point numbers. */
  convertValue(t) {
    return this.dtype == null || this.dtype === "float32" ? t : Math.round(t);
  }
  /** Returns true if less than 2-standard-deviations from the mean. */
  isValidTruncated(t) {
    return t <= this.upper && t >= this.lower;
  }
}
class d {
  constructor(t = 0, e = 1, a, s) {
    if (this.canReturnFloat = () => this.dtype == null || this.dtype === "float32", this.min = t, this.range = e - t, this.dtype = a, s == null && (s = Math.random()), typeof s == "number" && (s = s.toString()), !this.canReturnFloat() && this.range <= 1)
      throw new Error(`The difference between ${t} - ${e} <= 1 and dtype is not float`);
    this.random = h.alea(s);
  }
  convertValue(t) {
    return this.canReturnFloat() ? t : Math.round(t);
  }
  nextValue() {
    return this.convertValue(this.min + this.range * this.random());
  }
}
export {
  u as M,
  d as U
};
