How to resolve the algorithm Verify distribution uniformity/Naive step by step in the Erlang programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Verify distribution uniformity/Naive step by step in the Erlang 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 Erlang programming language
Source code in the erlang programming language
-module( verify_distribution_uniformity ).
-export( [naive/3] ).
naive( Generator, Times, Delta_percent ) ->
Dict = lists:foldl( fun update_counter/2, dict:new(), lists:duplicate(Times, Generator) ),
Values = [dict:fetch(X, Dict) || X <- dict:fetch_keys(Dict)],
Average = lists:sum( Values ) / dict:size( Dict ),
Delta = Average * (Delta_percent / 100),
Fun = fun(_Key, Value) -> erlang:abs(Value - Average) > Delta end,
Too_large_dict = dict:filter( Fun, Dict ),
return( dict:size(Too_large_dict), Too_large_dict, Average, Delta_percent ).
return( 0, _Too_large_dict, _Average, _Delta ) -> ok;
return( _N, Too_large_dict, Average, Delta ) ->
{error, {dict:to_list(Too_large_dict), failed_expected_average, Average, 'with_delta_%', Delta}}.
update_counter( Fun, Dict ) -> dict:update_counter( Fun(), 1, Dict ).
You may also check:How to resolve the algorithm Nth root step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the friendly interactive shell programming language
You may also check:How to resolve the algorithm Perfect numbers step by step in the REXX programming language
You may also check:How to resolve the algorithm Zumkeller numbers step by step in the Typescript programming language
You may also check:How to resolve the algorithm Literals/Integer step by step in the Oforth programming language