Message Boards Message Boards

1
|
5711 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Simple Dice Odds

Posted 12 years ago
For a personal project (and more help learning Mathematica), I'm looking to simulate rolls of customized six-sided dice with variable sides. For example, Die1 has faces of A, A, A, A, B, B and Die2 may have A, A, A, B, B, C. I'd like to be able to say how many times I roll a number of Die1 and a number of Die2 and how often each face (A, B, or C) turns up. Can someone please point me to the relevant functions? Thanks!
POSTED BY: Dave Lartigue
3 Replies
David, 

Also you may go to this link  to get a source code for tossing dice experiment. The demonstration website offers great amount of useful examples for your reference. 
POSTED BY: Shenghui Yang
Thanks, Sasha! That's exactly what I was looking for!
POSTED BY: Dave Lartigue
Dave,
RandomChoice[{a, a, a, a, b, b}, 6]
will simulate 6 throws of the first die, and
RandomChoice[{a, a, a, b, b, c}, 6]
will simulate 6 throws of the second die. This will generate 6 pairs of outcomes {die1, die2}
Transpose[{RandomChoice[{a, a, a, a, b, b}, 6], RandomChoice[{a, a, a, b, b, c}, 6]}]
Furthermore, Tally can be used to count them. For example for 10 thousands throw of two dice:
In[5]:= With[{n = 10^4}, Tally[Transpose[{RandomChoice[{a, a, a, a, b, b}, n], RandomChoice[{a, a, a, b, b, c}, n]}]]]
Out[5]= {{{a, a}, 3350}, {{b, a}, 1723}, {{a, b}, 2221}, {{b, b}, 1094}, {{a, c}, 1048}, {{b, c}, 564}}
Hope this helps,
Sasha 
POSTED BY: Oleksandr Pavlyk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract