Files
30-seconds-of-code/javascript/snippets/random-gauss.md
2023-05-01 22:35:56 +03:00

598 B

title, type, tags, cover, author, dateModified
title type tags cover author dateModified
Generate Gaussian random numbers snippet
math
random
chess-pawns chalarangelo 2023-04-03T05:00:00-04:00

Generates Gaussian (normally distributed) random numbers.

const randomGauss = () => {
  const theta = 2 * Math.PI * Math.random();
  const rho = Math.sqrt(-2 * Math.log(1 - Math.random()));
  return (rho * Math.cos(theta)) / 10.0 + 0.5;
};
randomGauss(); // 0.5