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)

/*REXX program simulates a 7─sided die based on a 5─sided throw for a number of trials. */
parse arg trials sample seed .                   /*obtain optional arguments from the CL*/
if trials=='' | trials=","  then trials=       1 /*Not specified?  Then use the default.*/
if sample=='' | sample=","  then sample= 1000000 /* "      "         "   "   "     "    */
if datatype(seed, 'W')  then call random ,,seed  /*Integer?  Then use it as a RAND seed.*/
L= length(trials)                                /* [↑]  one million samples to be used.*/
 
   do #=1  for trials;            die.= 0        /*performs the number of desired trials*/
   k= 0
               do  until k==sample;           r= 5 * random(1, 5)  +  random(1, 5)  -  6
               if r>20  then iterate
               k= k + 1;                      r= r // 7  +  1;          die.r= die.r + 1
               end   /*until*/
   say
   expect= sample % 7
   say center('trial:' right(#, L)    "   "     sample  'samples, expect' expect, 80, "─")
 
               do j=1  for 7
               say '      side'      j       "had "       die.j           ' occurrences',
                   '      difference from expected:'right(die.j - expect, length(sample) )
               end   /*j*/
   end   /*#*/                                   /*stick a fork in it,  we're all done. */