Verify distribution uniformity/Naive: Difference between revisions

Content deleted Content added
→‎{{header|OCaml}}: Added PureBasic
Line 333:
) h;
;;</lang>
=={{header|PureBasic}}==
<lang PureBasic>Prototype RandNum_prt()
 
Procedure.s distcheck(*function.RandNum_prt, repetitions, delta.d)
Protected text.s, maxIndex = 0
Dim bucket(maxIndex) ;array will be resized as needed
For i = 1 To repetitions ;populate buckets
v = *function()
If v > maxIndex
maxIndex = v
Redim bucket(maxIndex)
EndIf
bucket(v) + 1
Next
lbnd = Round((repetitions / maxIndex) * (100 - delta) / 100, #PB_Round_Up)
ubnd = Round((repetitions / maxIndex) * (100 + delta) / 100, #PB_Round_Down)
text = "Distribution check:" + #crlf$ + #crlf$
text + "Total elements = " + Str(repetitions) + #crlf$ + #crlf$
text + "Margin = " + StrF(delta, 2) + "% --> Lbound = " + Str(lbnd) + ", Ubound = " + Str(ubnd) + #crlf$
For i = 1 To maxIndex
If bucket(i) < lbnd Or bucket(i) > ubnd
text + #crlf$ + "Bucket " + Str(i) + " contains " + Str(bucket(i)) + " elements. Skewed."
EndIf
Next
ProcedureReturn text
EndProcedure
 
MessageRequester("Results", distcheck(@dice7(), 1000000, 0.20))</lang>
A small delta was chosen to increase the chance of a skewed result in the sample output:
<pre>Distribution check:
 
Total elements = 1000000
 
Margin = 0.20% --> Lbound = 142572, Ubound = 143142
 
Bucket 1 contains 141977 elements. Skewed.
Bucket 6 contains 143860 elements. Skewed.</pre>
 
=={{header|Python}}==