Verify distribution uniformity/Naive: Difference between revisions

Content deleted Content added
CL distribution checker
Line 68:
return 0;
}</lang>
 
=={{header|Common Lisp}}==
{{trans|OCaml}}
 
<lang lisp>(defun check-distribution (function n &optional (delta 1.0))
(let ((bins (make-hash-table)))
(loop repeat n do (incf (gethash (funcall function) bins 0)))
(loop with target = (/ n (hash-table-count bins))
for key being each hash-key of bins using (hash-value value)
when (> (abs (- value target)) (* 0.01 delta n))
do (format t "~&Distribution potentially skewed for ~w:~
expected around ~w got ~w." key target value)
finally (return bins))))</lang>
 
<pre>> (check-distribution #'(lambda () (random 10)) 1000)
Distribution potentially skewed for 3: expected around 100 got 111.
Distribution potentially skewed for 9: expected around 100 got 88.
T
#<EQL Hash Table{10} 200BDC1B>
 
> (check-distribution #'(lambda () (random 10)) 10000)
NIL
#<EQL Hash Table{10} 20090567></pre>
 
=={{header|OCaml}}==