Question: dice simulation with rand issue or trap

Something to be aware of.  I realized you can't use rand in an equation with other rand's since the calculation affects the other call to it. 

Here is an example:

A simulation of 3 six sided die rolls added together for 50 trials. 

with(Statistics):
a:=[]:
for i from 1 to 50 do
  b:=rand(1..6)()+rand(1..6)()+rand(1..6)():
  a:=[op(a),b]:
end do:
Histogram(a,frequencyscale=absolute,discrete=true)

You'll notice the rand calls have affected the other calls to rand, and has eliminated some possible results.  

[added by moderator, from a Reply by the OP]

The idea was to generate values from 1 to 20 (I just chose 20 as an example) using 6 sided dice, and one that which produces as uniform a distrubution as possible. I appreciate the explanations.  I chose 4 as the smallest number of rolls needed. In the physical world as n approaches large numbers rolling that many becomes increasingly more difficult and time consuming.

So just wondering what the best solution would be for a uniform distribution in a range from 1 to n using only six sided dice?

Please Wait...