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)

 
Module CheckIt {
      Def long i, calls, max, min
      s=stack:=random(1,5),random(1,5), random(1,5), random(1,5), random(1,5), random(1,5), random(1,5)
      z=0: for i=1 to 7 { z+=stackitem(s, i)} 
      dice7=lambda z, s -> {
            =((z-1) mod 7)+1 : stack s {z-=Number : data random(1,5): z+=Stackitem(7)}
      }
      Dim count(1 to 7)=0&  ' long type
      calls=700000
      p=0.05
      IsUniform=lambda max=calls/7*(1+p), min=calls/7*(1-p) (a)->{
            if len(a)=0 then =false : exit
            =false
            m=each(a)
            while m 
                  if array(m)<min or array(m)>max then break
            end while
            =true
      }
      For i=1 to calls {count(dice7())++}
      max=count()#max()
      expected=calls div 7
      min=count()#min()
      for i=1 to 7
      document doc$=format$("{0}{1::-7}",i,count(i))+{
      }
      Next i
      doc$=format$("min={0} expected={1} max={2}", min, expected, max)+{
      }+format$("Verify Uniform:{0}", if$(IsUniform(count())->"uniform", "skewed"))+{
      }
      Print
      report doc$
      clipboard doc$
}
CheckIt
 