#include "wled.h"

// Simple and fast Pseudo-Random-Number-Generator for 16bit and 8bit random numbers
// allows the same sequence of random numbers to be generated by setting the 16bit-seed
// values found by brute-force test algorithm: sequence has no repetitions and good randomness for its simplicity
class PRNG {
private:
  uint16_t seed;
public:
  PRNG(uint16_t initialSeed = 0x1234) : seed(initialSeed) {}
  void setSeed(uint16_t s) { seed = s; }
  uint16_t getSeed() const { return seed; }
  uint16_t random16() {
    seed = seed * 3001 + 31683;
    seed ^= seed >> 7;
    return seed;
  }
  uint16_t random16(uint16_t lim) { return ((uint32_t)random16() * lim) >> 16; }
  uint16_t random16(uint16_t min, uint16_t lim) { uint16_t delta = lim - min; return random16(delta) + min; }
  uint8_t random8() { return random16(); }
  uint8_t random8(uint8_t lim) { return (uint8_t)(((uint16_t)random8() * lim) >> 8); }
  uint8_t random8(uint8_t min, uint8_t lim) { uint8_t delta = lim - min; return random8(delta) + min; }
};
