function boxMuller(n) {
const samples = [];
Array(Math.ceil(n / 2)).fill().forEach(_ => {
const R = Math.sqrt(-2 * Math.log(Math.random()));
const theta = 2 * Math.PI * Math.random();
samples.push(R * Math.cos(theta));
samples.push(R * Math.sin(theta));
});
return samples.slice(0, n);
}