Verify distribution uniformity/Naive: Difference between revisions

Content added Content deleted
(Added zkl)
(Added Hy.)
Line 592: Line 592:
(5,(16526,True))
(5,(16526,True))
(6,(16670,True))</lang>
(6,(16670,True))</lang>

=={{header|Hy}}==

<lang lisp>(import [collections [Counter]])
(import [random [randint]])

(defn uniform? [f repeats delta]
; Call 'f' 'repeats' times, then check if the proportion of each
; value seen is within 'delta' of the reciprocal of the count
; of distinct values.
(setv bins (Counter (list-comp (f) [i (range repeats)])))
(setv target (/ 1 (len bins)))
(all (list-comp
(<= (- target delta) (/ n repeats) (+ target delta))
[n (.values bins)])))</lang>

Examples of use:

<lang lisp>(for [f [
(fn [] (randint 1 10))
(fn [] (if (randint 0 1) (randint 1 9) (randint 1 10)))]]
(print (uniform? f 5000 .02)))</lang>


=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==