pcgrandom.lua 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. ---@meta
  2. ---PcgRandom
  3. ------------
  4. -- A 32-bit pseudorandom number generator. Uses PCG32, an algorithm of the permuted
  5. -- congruential generator family, offering very strong randomness.
  6. ---@param seed number
  7. ---@param sequence number|nil
  8. ---@return mt.PcgRandom
  9. function PcgRandom(seed, sequence) end
  10. -- A 32-bit pseudorandom number generator. Uses PCG32, an algorithm of the permuted
  11. -- congruential generator family, offering very strong randomness.
  12. --
  13. -- It can be created via `PcgRandom(seed)` or `PcgRandom(seed, sequence)`.
  14. ---@class mt.PcgRandom
  15. local rnd = {}
  16. -- - Return next integer random number [`-2147483648`...`2147483647`].
  17. ---@param min integer|nil
  18. ---@param max integer|nil
  19. ---@return integer
  20. function rnd:next(min, max) end
  21. -- Return normally distributed random number [`min`...`max`].
  22. --
  23. -- This is only a rough approximation of a normal distribution with:
  24. --
  25. -- - `mean = (max - min) / 2`, and
  26. -- - `variance = (((max - min + 1) ^ 2) - 1) / (12 * num_trials)`
  27. -- - Increasing `num_trials` improves accuracy of the approximation.
  28. ---@param min number
  29. ---@param max number
  30. ---@param num_trials number
  31. ---@return integer
  32. function rnd:rand_normal_dist(min, max, num_trials) end