Add PcgRandom class

This commit is contained in:
Van
2026-09-08 22:31:03 +03:00
parent 0ed55757ce
commit 24d5e06910

40
classes/PcgRandom.lua Normal file
View File

@@ -0,0 +1,40 @@
---Version: 5.18
---@meta
---A 32-bit pseudorandom number generator.
---
---Uses PCG32, an algorithm of the permuted
---congruential generator family,
---offering very strong randomness.
---@class PcgRandom
---@overload fun(seed:integer, seq:integer?):PcgRandom
PcgRandom = {}
---Return next random integer number `[s32]`.
---@param max integer
---@param min integer
---@return integer
---@overload fun():integer
function PcgRandom:next(max, min) end
---Return normally distributed random number `[min...max]`.
---
---This is only a rough approximation of a normal distribution with:
---
---`mean = (max - min) / 2` and `variance = (((max - min + 1) ^ 2) - 1) / (12 * num_trials)`
---
---Increasing `num_trials` improves accuracy of the approximation
---@param max integer
---@param min integer
---@param num_trials integer
---@return integer
function PcgRandom:rand_normal_dist(max, min, num_trials) end
---Return generator state encoded in string.
---@return string
function PcgRandom:get_state() end
---Restore generator state from encoded string.
---@param state_string string
---@return string
function PcgRandom:set_state(state_string) end