Skip to content

Instantly share code, notes, and snippets.

@cosinewaves
Created August 19, 2025 15:45
Show Gist options
  • Save cosinewaves/0c298ccd241fb774410b4f55398e59b4 to your computer and use it in GitHub Desktop.
Save cosinewaves/0c298ccd241fb774410b4f55398e59b4 to your computer and use it in GitHub Desktop.
gaussianRandom
local function gaussianRandom(mean: number, stddev: number): number
-- Box-Muller transform
local u1 = math.random()
local u2 = math.random()
-- z is standard normal (mean 0, stddev 1)
local z = math.sqrt(-2 * math.log(u1)) * math.cos(2 * math.pi * u2)
-- scale + shift
return mean + z * stddev
end
return gaussianRandom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment