Javascript examples for Math:random
Generate random number with a non-uniform distribution, poisson Random Number
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){// w w w . j a va2s .c om function poissonRandomNumber(lambda) { var L = Math.exp(-lambda), k = 0, p = 1; do { k = k + 1; p = p * Math.random(); } while (p > L); return k - 1; } document.getElementById("result").textContent = poissonRandomNumber(100); } </script> </head> <body> <div id="result"></div> </body> </html>