Script Categories













Calculators >>> Random Distribution.

Generate normally distributed random numbers by entering a mean value and standard deviation. Uses the normal law of error to determine an events given probability.

GENERATION OF A RANDOM SET OF NORMALLY DISTRIBUTED VALUES
Normal Law Universe Parameters
Mean value = Std. Deviation =
Number of points to generate =
Calculated Random Sample values
Calculated Sample Properties

Mean value =
Std. Deviation =

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function calculate() {
var mean, sdev, N, sign, sum, str;
var y = Array(), x = Array(), freq = Array();
mean = document.statForm.m.value * 1;
sdev = document.statForm.s.value * 1;
N = document.statForm.n.value * 1;
sdevsq = sdev * sdev;
for(var i = 0; i <= N; i++) {
yr = 1;
yxr = 0;
while(yr > yxr) {
xr = 500 * sdev * Math.random();
yr = 100 * Math.random();
yxr = 100 * Math.exp(-(xr) * (xr) / (2 * sdevsq));
}
s = 1;
if(Math.random() < .5)
s = -1;
x[i] = mean + s * xr;
}
str = "";
for(var i = 1; i <= N; i++) {
str = str + x[i] + "\n";
}
sum = 0;
for(var i = 1; i <= N; i++) {
sum = sum + x[i];
}
mean = sum / N;
sum = 0;
for(var i = 1; i <= N; i++) {
sum = sum + (x[i] - mean) * (x[i] - mean)
}
sdev = Math.sqrt((sum) / (N - 1));
document.statForm.vals.value = str;
document.statForm.mm.value = mean;
document.statForm.ss.value = sdev;
}
//  End -->
</script>
<form name=statForm>
<table cellpadding=0 bgcolor=black>
<tr>
<td>
<table
border=0 cellpadding=5 bgcolor=ffffcc>
<tr>
<td
colspan=2>
<center>
<
font face=arial size=2>
<
b>GENERATION OF A RANDOM SET OF NORMALLY DISTRIBUTED VALUES</b>
<
/font>
<
/center>
</td>
</tr>
<tr>
<td
colspan=2>
<center>
<
b>Normal Law Universe Parameters
</center>
</td>
</tr>
<tr>
<td>
<b>Mean value = <input type=text  name="m" size=15></b>
</td>
<td>
<b>Std. Deviation = <input type=text name="s" size=15></b>
</td>
</tr>
<tr>
<td
colspan=2 nowrap=>
<center>
<
b>Number of points to generate = <input type=text name="n" size=10></b>
<input type=button value="Generate Sample" onClick="calculate()">
</center>
</td>
</tr>
<tr>
<td
nowrap>
<center>
<
b>Calculated Random Sample values</b>
<
br>
<textarea name=vals rows=5 cols=20></textarea>
</center>
</td>
<td
valign=top>
<center>
<
b>Calculated Sample Properties</b>
<
br>
<
br>
<
b>
<table border="0">
   <tr>
      <td nowrap>Mean value   = </td>
      <td><input type=text name="mm" size=20></td>
   </tr>
   <tr>
      <td nowrap>Std. Deviation = </td>
      <td><input type=text name="ss" size=20></td>
   </tr>
</table>
</b>
<
/center>
<
br>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).

R7


©