Created
August 19, 2025 15:45
-
-
Save cosinewaves/0c298ccd241fb774410b4f55398e59b4 to your computer and use it in GitHub Desktop.
gaussianRandom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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