Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63043845
test_random_normal_distr.html
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, May 17, 09:46
Size
1 KB
Mime Type
text/html
Expires
Sun, May 19, 09:46 (2 d)
Engine
blob
Format
Raw Data
Handle
17724884
Attached To
R5099 Antibiotics effects
test_random_normal_distr.html
View Options
<!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
Log In to Comment