diff options
author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-06 14:35:04 -0700 |
---|---|---|
committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2024-03-06 14:35:04 -0700 |
commit | 823620b2a6ebb7ece619991e47a37ad46542b69f (patch) | |
tree | 82a1501c5f707a1bcbc6c28bd6d0f5731cc9f618 /src/engine/utils/random.ts | |
parent | ce06fa7c29ba4e3d6137f7aa74fbfe45af0e8b73 (diff) | |
download | the-abstraction-engine-823620b2a6ebb7ece619991e47a37ad46542b69f.tar.gz the-abstraction-engine-823620b2a6ebb7ece619991e47a37ad46542b69f.zip |
add particles
Diffstat (limited to 'src/engine/utils/random.ts')
-rw-r--r-- | src/engine/utils/random.ts | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/engine/utils/random.ts b/src/engine/utils/random.ts new file mode 100644 index 0000000..3d9d8b8 --- /dev/null +++ b/src/engine/utils/random.ts @@ -0,0 +1,9 @@ +export const normalRandom = (mean: number, stdDev: number, maxStdDevs = 2) => { + const [u, v] = [0, 0].map(() => Math.random() + 1e-12); + const normal = + mean + stdDev * Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v); + return Math.min( + mean + maxStdDevs * stdDev, + Math.max(mean - maxStdDevs * stdDev, normal), + ); +}; |