Example 3.1 Figure 3.10 p.31

<< Graphics`Graphics`

p = {0, 0, 0, 0, 0, 0}; ne = 0; n = 100;

Do[{r = Random[Integer, {1, 6}]; p[[r]] = p[[r]] + 1, 
        If[Mod[r, 2] == 0, ne = ne + 1]}, {i, 1, 
        n}]
Print["p=", p = N[p/n], " ne=", N[ne/n]]

BarChart[p, PlotRange ->  {0, 0.3}]

Example 3.1 別解  Figure 3.10   p.31

<< Graphics`Graphics`

p = {0, 0, 0, 0, 0, 0}; n = 100;

Do[{r = Random[Integer, {1, 6}]; 
        If[r == 1, p = p + {1, 0, 0, 0, 0, 0}, 
          If[r == 2, p = p + {0, 1, 0, 0, 0, 0}, 
            If[r == 3, p = p + {0, 0, 1, 0, 0, 0}, 
              If[r == 4, p = p + {0, 0, 0, 1, 0, 0}, 
                If[r == 5, p = p + {0, 0, 0, 0, 1, 0}, 
                  p = p + {0, 0, 0, 0, 0, 1}]]]]]}, {i, 1, 
        n}]
p = N[p/n]

BarChart[p, PlotRange ->  {0, 0.3}]