From a Reply, I see that you really want to generate discrete uniform random numbers from 1..120 using a 6-sided die (note that *dice* is strictly plural, like *mice *and *lice*). The process can be simplified because 120 can be expressed as a product of positive integers all <= 6; specifically, 120 = 4*5*6. (Number theorists would say that 120 is {2, 3, 5}-*smooth*, the {2, 3, 5} being the primes <= 6.) Since those are three factors, it'll often be possible with three rolls of the 6-sided die. However, sometimes a roll will need to be discarded and rerolled. The expected number of rolls is exactly 3.7 (Maple-based proof below).

I use a multi-radix representation. This is similar to an alternate-base representation, but with a different base for each digit position. For any **n in** **{$120}**, there exists a *unique* triple **[d4, d5, d6] **such that

**n = 1 + 5*6*(d4 - 1) + 6*(d5 - 1) + (d6 - 1)**, (formula 1)

where **d4 in {$4}**,** d5 in {$5}**,** **and **d6 in {$6}**^{[*1] }(proof outline in footnote). I developed this formula to make the arithmetic simple enough for your son. So, how do we generate **d4 **and **d5 ***uniformly *with a 6-sided die? For **d4**, roll the die, perhaps repeatedly, until it gives a number <= 4; for **d5**, do the analogous thing. The expected number of rolls for **d_k **(i.e., **d4**, **d5**, etc.) is

**sum(n*k/s*(1 - k/s)^(n-1), n= 1..infinity) assuming 0 < k, k <= s**,

where **s** is the number of sides on the actual die, and **n** runs over all possible numbers of rolls. The sum simplifies to **s/k**, as you can check with Maple. (You can also look up the *negative binomial *distribution in *Wikipedia*.) So, in this particular case the expected number of rolls to get all three "digits" is **6/4 + 6/5 + 6/6 = 37/10 = 3.7**.

If **n** is not {2, 3, 5}-smooth, a slightly more-complicated process can be used, and the expected number of rolls will be slightly more.

Here's a Maple simulation for **n = 120**, which I coded to be easily modifiable to other numbers of sides of the die and appropriately smooth values of **n**.

**restart
:
Roll_120:= module()
local
sides::And(posint, Not(1)):= 6,
ds:= rand(1..sides),
roll:= (k::And(posint, Not(1)))-> local r;
do Roll_Ct++; if (r:= ds()) <= k then return r fi od,
radices:= [4,5,6], ****#4*5*6 = 120****
Coeffs:= (P-> P[-1]/~P)([seq[scan= `*`]](radices)) ****#[30, 6, 1]****
;
export
ModuleApply:= ()-> (R-> R = 1 + inner(R-~1, Coeffs))(roll~(radices)),
ExpectedRolls:= add(sides/~radices), ****#expected # of rolls per turn**
**Roll_Ct:= 0** **#Count the rolls only to verify expectation.**
**;
end module
:
****#Choose the hockey team!:****
'Roll_120'() $ 5;**
[2, 5, 6] = 60, [2, 3, 4] = 46, [4, 5, 3] = 117, [1, 5, 2] = 26, [3, 2, 2] = 68
**#If a card number were repeated, we'd simply reroll for that card.**
**Roll_120:-ExpectedRolls;**
37 / 10
**#Performance test for 100,000 triples:**
**Roll_120:-Roll_Ct:= 0:
Rolls:= CodeTools:-Usage([to 10^5 do Roll_120() od]):**
memory used=74.07MiB, alloc change=-3.01MiB,
cpu time=766.00ms, real time=727.00ms, gc time=62.50ms
**Roll_120:-Roll_Ct;** **#Check expected roll count.**
369526
**#Check uniformity:**
**RRolls:= rhs~(Rolls):
[{Statistics:-Tally(RRolls)[]}[]];**
[1 = 785, 2 = 822, 3 = 821, 4 = 827, 5 = 777, 6 = 806, 7 = 874, 8 = 857, 9 = 823, 10 = 837,
11 = 827, 12 = 811, 13 = 856, 14 = 820, 15 = 791, 16 = 874, 17 = 861, 18 = 848, 19 = 796, 20 = 855,
21 = 850, 22 = 826, 23 = 856, 24 = 845, 25 = 861, 26 = 829, 27 = 806, 28 = 890, 29 = 787, 30 = 846,
31 = 873, 32 = 841, 33 = 836, 34 = 853, 35 = 855, 36 = 854, 37 = 779, 38 = 842, 39 = 854, 40 = 827,
41 = 903, 42 = 814, 43 = 816, 44 = 797, 45 = 829, 46 = 835, 47 = 854, 48 = 819, 49 = 861, 50 = 868,
51 = 824, 52 = 802, 53 = 781, 54 = 880, 55 = 802, 56 = 858, 57 = 826, 58 = 867, 59 = 807, 60 = 839,
61 = 851, 62 = 798, 63 = 843, 64 = 828, 65 = 832, 66 = 794, 67 = 850, 68 = 821, 69 = 821, 70 = 812,
71 = 809, 72 = 831, 73 = 819, 74 = 805, 75 = 811, 76 = 842, 77 = 805, 78 = 850, 79 = 816, 80 = 799,
81 = 809, 82 = 851, 83 = 805, 84 = 863, 85 = 818, 86 = 841, 87 = 863, 88 = 893, 89 = 865, 90 = 784,
91 = 840, 92 = 808, 93 = 833, 94 = 851, 95 = 889, 96 = 797, 97 = 843, 98 = 804, 99 = 798, 100 = 856,
101 = 862, 102 = 826, 103 = 840, 104 = 883, 105 = 825, 106 = 882, 107 = 879, 108 = 799, 109 = 804, 110 = 851,
111 = 834, 112 = 852, 113 = 819, 114 = 807, 115 = 861, 116 = 846, 117 = 829, 118 = 837, 119 = 825, 120 = 831]
**nops(%), add(rhs~(%));**
120, 100000
**Statistics:-Histogram(RRolls, discrete, frequencyscale= absolute, size= 70*[8,3]);**

The process that you show in the Question has two major mathematical errors. (This is totally independent of the Maple problem of automatic simplification / premature evaluation that's already been addressed.):

- A sum of independent nonconstant uniform random variables can never be uniform.
- If
**r** is a discrete uniform random variable on **1..n**, then **r mod d** can only be uniform if **d** divides **n **(or, quite trivially, if **abs(d) > n**).

Footnote:

**[*1]** Outline of a proof of the existence and uniqueness of the multi-radix representation

**n = 1 + 5*6*(d4 - 1) + 6*(d5 - 1) + (d6 - 1)**.

Let **d6:= irem(n-1, 6, 'q') + 1**, **d5:= irem(q, 5, 'q') + 1**, **d4:= irem(q, 4) + 1**. Each of these steps is defined and produces a unique value.