mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-09 13:08:49 +02:00
* extended with a Chi square test to check if the random values are equally distributed
This commit is contained in:
parent
39f7172ee8
commit
5a59ffdca7
@ -1,8 +1,12 @@
|
||||
{ %INTERACTIVE }
|
||||
program test_random;
|
||||
|
||||
const
|
||||
buckets = 1000000;
|
||||
repeats = 20;
|
||||
var
|
||||
i: integer;
|
||||
hist : array[1..buckets] of LongInt;
|
||||
i : longint;
|
||||
chisquare : extended;
|
||||
begin
|
||||
randomize;
|
||||
WriteLn('Random Values II:');
|
||||
@ -16,4 +20,20 @@ begin
|
||||
begin
|
||||
WriteLn(Random(100));
|
||||
end;
|
||||
|
||||
{ do a Chi^2 test, hopefully I got it right }
|
||||
fillchar(hist,sizeof(hist),0);
|
||||
for i:=1 to buckets*repeats do
|
||||
inc(hist[longint(trunc(random*buckets)+1)]);
|
||||
|
||||
chisquare:=0.0;
|
||||
for i:=low(hist) to high(hist) do
|
||||
chisquare:=chisquare+sqr(hist[i]-repeats)/repeats;
|
||||
writeln(chisquare);
|
||||
|
||||
{ m=1000000; p=0.1 }
|
||||
if chisquare>1001741 then
|
||||
halt(1)
|
||||
else
|
||||
writeln('ok');
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user