Task

(Given an equal-probability generator of one of the integers 1 to 5
as dice5),   create dice7 that generates a pseudo-random integer from
1 to 7 in equal probability using only dice5 as a source of random
numbers,   and check the distribution for at least one million calls using the function created in   Simple Random Distribution Checker.


Implementation suggestion:
dice7 might call dice5 twice, re-call if four of the 25
combinations are given, otherwise split the other 21 combinations
into 7 groups of three, and return the group index from the rolls.

(Task adapted from an answer here)

 
n=1000000    '1000000 would take several minutes
print "Testing ";n;" times"
if  not(check(n, 0.05)) then print "Test failed" else print "Test passed"
end
 
'function check(n, delta) is defined at
'http://rosettacode.org/wiki/Verify_distribution_uniformity/Naive#Liberty_BASIC
 
function GENERATOR()
    'GENERATOR = int(rnd(0)*10) '0..9
    'GENERATOR = 1+int(rnd(0)*5) '1..5: dice5
 
    'dice7()
    do
        temp =dice5() *5 +dice5() -6
    loop until temp <21
    GENERATOR =( temp mod 7) +1
 
end function
 
function dice5()
    dice5=1+int(rnd(0)*5) '1..5: dice5
end function
 