How to resolve the algorithm Verify distribution uniformity/Naive step by step in the VBScript programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Verify distribution uniformity/Naive step by step in the VBScript 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 VBScript programming language

Source code in the vbscript programming language

Option Explicit

sub verifydistribution(calledfunction, samples, delta)
	Dim i, n, maxdiff
	'We could cheat via Dim d(7), but "7" wasn't mentioned in the Task. Heh.
	Dim d : Set d = CreateObject("Scripting.Dictionary")
	wscript.echo "Running """ & calledfunction & """ " & samples & " times..."
	for i = 1 to samples
		Execute "n = " & calledfunction
		d(n) = d(n) + 1
	next
	n = d.Count
	maxdiff = 0
	wscript.echo "Expected average count is " & Int(samples/n) & " across " & n & " buckets."
	for each i in d.Keys
		dim diff : diff = abs(1 - d(i) / (samples/n))
		if diff > maxdiff then maxdiff = diff
		wscript.echo "Bucket " & i & " had " & d(i) & " occurences" _
		& vbTab & " difference from expected=" & FormatPercent(diff, 2)
	next
	wscript.echo "Maximum found variation is " & FormatPercent(maxdiff, 2) _
		& ", desired limit is " & FormatPercent(delta, 2) & "."
	if maxdiff > delta then wscript.echo "Skewed!" else wscript.echo "Smooth!"
end sub

verifydistribution "dice7", 1000, 0.03
verifydistribution "dice7", 100000, 0.03

  

You may also check:How to resolve the algorithm Rot-13 step by step in the Phix programming language
You may also check:How to resolve the algorithm Vigenère cipher step by step in the Zig programming language
You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Loops/For step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Bitwise IO step by step in the PL/I programming language