@@ -337,6 +337,7 @@ export function initGlobalStrandsAPI(p5, fn, strandsContext) {
337337 const originalNoise = fn . noise ;
338338 const originalNoiseDetail = fn . noiseDetail ;
339339 const originalRandom = fn . random ;
340+ const originalRandomGaussian = fn . randomGaussian ;
340341 const originalRandomSeed = fn . randomSeed ;
341342 const originalMillis = fn . millis ;
342343
@@ -480,6 +481,20 @@ export function initGlobalStrandsAPI(p5, fn, strandsContext) {
480481 }
481482 } ) ;
482483
484+ augmentFn ( fn , p5 , 'randomGaussian' , function ( ...args ) {
485+ if ( ! strandsContext . active ) {
486+ return originalRandomGaussian . apply ( this , args ) ;
487+ }
488+ const mean = args . length >= 1 ? args [ 0 ] : 0 ;
489+ const stdDev = args . length >= 2 ? args [ 1 ] : 1 ;
490+
491+ const u1 = this . max ( this . random ( ) , 1e-6 ) ;
492+ const u2 = this . random ( ) ;
493+ const z = this . sqrt ( this . log ( u1 ) . mult ( - 2 ) ) . mult ( this . cos ( u2 . mult ( 2 * Math . PI ) ) ) ;
494+
495+ return z . mult ( stdDev ) . add ( mean ) ;
496+ } ) ;
497+
483498 augmentFn ( fn , p5 , 'millis' , function ( ...args ) {
484499 if ( ! strandsContext . active ) {
485500 return originalMillis . apply ( this , args ) ;
0 commit comments