26 lines
622 B
Plaintext
26 lines
622 B
Plaintext
$ include "seed7_05.s7i";
|
|
include "float.s7i";
|
|
include "math.s7i";
|
|
|
|
const func float: frand is func # Uniform distribution, (0..1]
|
|
result
|
|
var float: frand is 0.0;
|
|
begin
|
|
repeat
|
|
frand := rand(0.0, 1.0);
|
|
until frand <> 0.0;
|
|
end func;
|
|
|
|
const func float: randomNormal is # Normal distribution, centered on 0, std dev 1
|
|
return sqrt(-2.0 * log(frand)) * cos(2.0 * PI * frand);
|
|
|
|
const proc: main is func
|
|
local
|
|
var integer: i is 0;
|
|
var array float: rands is 1000 times 0.0;
|
|
begin
|
|
for i range 1 to length(rands) do
|
|
rands[i] := 1.0 + 0.5 * randomNormal;
|
|
end for;
|
|
end func;
|