RosettaCodeData/Task/Random-numbers/Elena/random-numbers.elena

36 lines
653 B
Text
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
import extensions;
import extensions'math;
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
randomNormal()
{
2020-02-17 23:21:07 -08:00
^ cos(2 * Pi_value * randomGenerator.nextReal())
* sqrt(-2 * ln(randomGenerator.nextReal()))
2019-09-12 10:33:56 -07:00
}
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
public program()
{
real[] a := new real[](1000);
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
real tAvg := 0;
for (int x := 0, x < a.Length, x += 1)
{
a[x] := (randomNormal()) / 2 + 1;
tAvg += a[x]
};
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
tAvg /= a.Length;
console.printLine("Average: ", tAvg);
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
real s := 0;
for (int x := 0, x < a.Length, x += 1)
{
2020-02-17 23:21:07 -08:00
s += power(a[x] - tAvg, 2)
2019-09-12 10:33:56 -07:00
};
2018-06-22 20:57:24 +00:00
2020-02-17 23:21:07 -08:00
s := sqrt(s / 1000);
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
console.printLine("Standard Deviation: ", s);
2018-06-22 20:57:24 +00:00
2019-09-12 10:33:56 -07:00
console.readChar()
}