Verify distribution uniformity/Naive: Difference between revisions

Content deleted Content added
Line 364:
 
=={{header|Euler Math Toolbox}}==
 
Following the task commands.
 
<lang>
>function checkrandom (frand$, n:index, delta:positive real) ...
$ v=zeros(1,n);
$ loop 1 to n; v{#}=frand$(); end;
$ K=max(v);
$ fr=getfrequencies(v,1:K);
$ return max(fr/n-1/K)<delta/sqrt(n);
$ endfunction
>function dice () := intrandom(1,1,6);
>checkrandom("dice",1000000,1)
1
>wd = 0|((1:6)+[-0.01,0.01,0,0,0,0])/6
[ 0 0.165 0.335 0.5 0.666666666667 0.833333333333 1 ]
>function wrongdice () := find(wd,random())
>checkrandom("wrongdice",1000000,1)
0
</lang>
 
Checking the dice7 from dice5 generator.
 
<lang>
>function dice5 () := intrandom(1,1,5);
>function dice7 () ...
$ repeat
$ k=(dice5()-1)*5+dice5();
$ if k<=21 then return ceil(k/3); endif;
$ end;
$ endfunction
>checkrandom("dice7",1000000,1)
1
</lang>
 
Faster implementation with the matrix language.
 
<lang>
>function dice5(n) := intrandom(1,n,5)-1;
>function dice7(n) ...
$ v=dice5(2*n)*5+dice5(2*n);
$ return v[nonzeros(v<=21)][1:n];
$ endfunction
>test=dice7(1000000);
>function checkrandom (v, delta=1) ...
$ K=max(v); n=cols(v);
$ fr=getfrequencies(v,1:K);
$ return max(fr/n-1/K)<delta/sqrt(n);
$ endfunction
>checkrandom(test)
1
</lang>
 
=={{header|Fortran}}==