How to resolve the algorithm Verify distribution uniformity/Naive step by step in the PureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Verify distribution uniformity/Naive step by step in the PureBasic programming language
Table of Contents
Problem Statement
This task is an adjunct to Seven-sided dice from five-sided dice.
Create a function to check that the random integers returned from a small-integer generator function have uniform distribution.
The function should take as arguments:
The function should produce:
Show the distribution checker working when the produced distribution is flat enough and when it is not. (Use a generator from Seven-sided dice from five-sided dice).
See also:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Verify distribution uniformity/Naive step by step in the PureBasic programming language
Source code in the purebasic programming language
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))
You may also check:How to resolve the algorithm 15 puzzle game step by step in the VBScript programming language
You may also check:How to resolve the algorithm Exceptions/Catch an exception thrown in a nested call step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Word frequency step by step in the KAP programming language
You may also check:How to resolve the algorithm Averages/Median step by step in the BASIC programming language
You may also check:How to resolve the algorithm Poker hand analyser step by step in the C++ programming language