One Minute One-liners for the curious: https://www.youtube.com/@1minute1liners
In this YouTube short from One Minute One-liners for the curious(@1minute1liner), I explain how to write a Gaussian random number generator from scratch. We start with a one-liner of the Box-Muller method stated here as an anonymous function:
bmrandn1=@(b) sqrt(-2*log(rand(1,b))).*cos(2*pi*rand(1,b));
An alternative is the one line anonymous function using erfinv:
cdfrandn=@(b) sqrt(2)*erfinv(2*rand(1,b)-1);
Below are the illustrative functions bmrandn.m and erfinv1.m.
Original Box-Muller paper: https://doi.org/10.1214%2Faoms%2F1177706645
Table based erfinv function: https://people.maths.ox.ac.uk/gilesm/codes/erfinv/
D'Agostino-Pearson code in Matlab Central: https://www.mathworks.com/matlabcentral/fileexchange/3954-dagosptest?s_tid=srchtitle