Unbias a random generator: Difference between revisions

→‎{{header|GAP}}: seems it was not obvious
(→‎{{header|GAP}}: Marked incomplete. Full range not used. (After deciphering what output is given).)
(→‎{{header|GAP}}: seems it was not obvious)
Line 117:
 
=={{header|GAP}}==
{{incomplete|GAP|For N over its range, generate and show counts of the outputs of randN and unbiased(randN)}}
<lang gap>RandNGen := function(n)
local v, rand;
Line 144 ⟶ 143:
end;
 
arange := RandNGen([2) .. 6];
bv := RandNGenList(5range, RandNGen);
cw := UnbiasedGenList(av, UnbiasedGen);
apply := gen -> Sum([1 .. 1000000], n -> agen());
d := UnbiasedGen(b);
 
# Some tests (2 is added as a witness, since in this case RandN is already unbiased)
Sum([1 .. 1000000], n -> a());
PrintArray(TransposedMat([range, List(v, apply), List(w, apply)]));
# 500105
# [ [ 2, 499991, 499041 ],
 
# [ 3, 333310, 500044 ],
Sum([1 .. 1000000], n -> b());
# [ 4, 249851, 500663 ],
# 200512
# [ 5, 200532, 500448 ],
 
# [ 6, 166746, 499859 ] ]</lang>
Sum([1 .. 1000000], n -> c());
# 500158
 
Sum([1 .. 1000000], n -> d());
# 499752</lang>
 
=={{header|J}}==
506

edits