Rolling three dice and show the probabilities Roll 3 dice, count the two highest two values and add them to the result. Every 1 must be rolled once again.

Now show the average throw after 1000000 tries and the probabilities for each result occurring:

Desired Result:


  avg(9.095855)
  2: 0.0023
  3: 0.0448
  4: 1.1075
  5: 2.8983
  6: 6.116
  7: 10.1234
  8: 15.4687
  9: 18.9496
  10: 19.3575
  11: 16.0886
  12: 9.8433
Mathematica 150 146 94 115 108
Edit: This version is a suggestion from @belisarius.  Much shorter and faster than my own code (found in the earlier versions).
r=RandomInteger;t=Tr/@Rest/@Sort/@(5~r~{10^6,3}/. 0:&gt;r[5]);
{Mean@t+2,{#[[1]]+2,#[[2]]/10^4}&amp;/@Sort@Tally@t}//N


{9.09684, {{2., 0.0028}, {3., 0.0456}, {4., 1.1097}, {5., 2.8752}, {6., 6.1246}, {7., 10.122},
{8., 15.513}, {9., 18.8956}, {10., 19.3514}, {11., 16.074}, {12., 9.8861}}}