This just uses your code and shows its result... please run the code below and tell me if the results give a Normal Distribution (or gaussian distribution (which looks the same
))
Someone please post thier result... thanks (you should get at least 30,000 in your sample to show a reasonable level of confidence in your results)
Code:
{.include \srl\srl.scar}
function findgaussian(min, max : integer) : integer;
var
values : array[-16..16] of extended;
e, a, mypi, b, total, selected:extended;
i,margin : integer;
begin
e := 2.718281828
mypi := 3.1415926535897932354626433832795 {from memory}
a := 2*mypi;
a := sqrt(a);
i := 1;
b := 1875;
b := b/10000;
for i:=-16 to 16 do
values[i] := pow(e, -pow((b*i),2)/2)/a;
selected := random(4919578);
selected:=selected/1000000;
i:=-16;
total:=0;
while(i<=16) and (selected > total) do
begin
total := total+values[i];
i:=i+1;
end
margin:= (max-min)/32;
Result := random(margin)+margin*(i+16)+min;
if margin=0 then
Result:=random(max-min)+min;
end;
procedure TestFindGaussian(TotalNum: Integer);
var
i, temp, count: Integer;
Num: Array of Integer;
begin
setarraylength(Num, TotalNum);
repeat
Count := Count + 1;
temp := findgaussian(0, (TotalNum));
Num[temp] := Num[temp] + 1;
if Count mod 1000 = 0 then
begin
ClearDebug;
Writeln('Result in % press q to quiet Total sample size: ' + inttostr(Count));
for i := 0 to (TotalNum - 1) do
begin
writeln(inttostr(i) + ' --> ' + inttostr(round(Num[i]/Count*100)) + '%');
end;
writeln('');
end;
until IsKeyDown('q') or IsKeyDown('Q');
end;
begin
TestFindGaussian(strtoint(Readln('Total number of digets to test (try 10)')));
end.