Page MenuHomec4science

test_random_normal_distr.html
No OneTemporary

File Metadata

Created
Fri, May 17, 09:46

test_random_normal_distr.html

<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<div id="tester" style="width:600px;height:250px;"></div>
<body>
<script>
var random_numbers=[];
function random_from_normal_distribution(mean, variance) {
var u1 = Math.random(); // should belong to ]0,1]
if (u1==0){
u1=1;
}
var u2 = Math.random(); // should belong to ]0,1]
if (u2==0){
u2=1;
}
theta=2*3.14*u2;
var r= Math.sqrt(-2*Math.log(u1));
var x=r*Math.cos(theta);
var y=r*Math.sin(theta);
x = mean + Math.sqrt(variance) * x;
// return only one of the two normal random variable generated
return x;
}
for (var i=1; i<1000; i++){
rand=1/random_from_normal_distribution(150, 0.05*150);
random_numbers.push(rand);
}
var data = [
{
y: random_numbers,
type: 'histogram',
marker: {
color: 'blue',
},
}
];
TESTER = document.getElementById('tester');
Plotly.newPlot(TESTER, data);
</script>
</body>
</html>

Event Timeline