/**
 * Thin wrapper over Phaser's seedable RandomDataGenerator (Phaser.Math.RND).
 * IMPORTANT: Phaser.Math.Between / FloatBetween use Math.random and are NOT
 * seedable — gameplay spawning must use these helpers so a seed fully
 * determines a run (Daily Challenge). Cosmetic randomness (particles) may keep
 * Math.random.
 */
export const rng = {
  seed(value) {
    Phaser.Math.RND.sow([String(value)]);
  },

  /** Random float [0, 1). */
  frac() {
    return Phaser.Math.RND.frac();
  },

  /** Integer in [min, max] inclusive. */
  between(min, max) {
    return Phaser.Math.RND.between(min, max);
  },

  /** Float in [min, max). */
  realBetween(min, max) {
    return Phaser.Math.RND.realInRange(min, max);
  },

  /** Random element of an array. */
  pick(arr) {
    return Phaser.Math.RND.pick(arr);
  },

  /** +1 or -1. */
  sign() {
    return Phaser.Math.RND.frac() < 0.5 ? 1 : -1;
  },
};

/** Returns today's date as a YYYY-MM-DD string (local time) for daily seeds. */
export function todaySeed() {
  const d = new Date();
  const mm = String(d.getMonth() + 1).padStart(2, '0');
  const dd = String(d.getDate()).padStart(2, '0');
  return `${d.getFullYear()}-${mm}-${dd}`;
}
