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)

 
$include "distribution-checker.icn"
 
# return a uniformly distributed number from 1 to 7,
# but only using a random number in range 1 to 5.
procedure die_7 ()
  while rnd := 5*?5 + ?5 - 6 do {
    if rnd < 21 then suspend rnd % 7 + 1
  }
end
 
procedure main ()
  if verify_uniform (create (|die_7()), 1000000, 0.01)
    then write ("uniform")
    else write ("skewed")
end
 