Verify distribution uniformity/Naive: Difference between revisions

no edit summary
(Allowing a generator object as well as a generator function so languages without first-class functions aren't omitted)
No edit summary
Line 17:
'''See also:'''
*[[Verify Distribution Uniformity with Chi-Squared Test‎]]
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>result := DistCheck("dice7",10000,3)
MsgBox, % result
 
DistCheck(function, repetitions, delta)
{ Loop, % 7 ; initialize array
{ bucket%A_Index% := 0
}
 
Loop, % repetitions ; generate numbers
{ v := %function%()
bucket%v% += 1
}
 
lbnd := round((repetitions/7)*(100-delta)/100)
ubnd := round((repetitions/7)*(100+delta)/100)
text := "Distribution check:`n`nTotal elements = " repetitions "`n`nMargin = " delta "% --> Lbound = " lbnd ", Ubound = " ubnd "`n"
Loop, % 7
{ text := text "`nBucket " A_Index " contains " bucket%A_Index% " elements."
If bucket%A_Index% not between %lbnd% and %ubnd%
text := text " Skewed."
}
Return, text
}</lang>
<pre>Distribution check:
 
Total elements = 10000
 
Margin = 3% --> Lbound = 1386, Ubound = 1471
 
Bucket 1 contains 1450 elements.
Bucket 2 contains 1374 elements. Skewed.
Bucket 3 contains 1412 elements.
Bucket 4 contains 1465 elements.
Bucket 5 contains 1370 elements. Skewed.
Bucket 6 contains 1485 elements. Skewed.
Bucket 7 contains 1444 elements.</pre>
 
=={{header|C}}==
Anonymous user