1
$\begingroup$

I am looking to output the probability of n classic six-sided dice but I am not sure how to go about starting. This is what I have written out so far, but no way to go about accounting for n dice for every roll.

Dice[n_Integer] := Dice[n, Black]
Format[Dice[n_Integer, c_]] := 
 With[{dots = {1 -> {5}, 2 -> {3, 7}, 3 -> {3, 5, 7}, 
      4 -> {1, 3, 7, 9}, 5 -> {1, 3, 5, 7, 9}, 
      6 -> {1, 2, 3, 7, 8, 9}} /. 
     l : {__Integer} :> 
      Sequence @@ Thread[l -> Graphics[{c, Disk[]}, ImageSize -> 16]],
    face = Partition[Range@9, 3]}, 
  Panel[Grid[face /. {n /. dots, _Integer -> Null}, ItemSize -> All]]]
Dice /@ Range@6 // Row

RollDice[] := GraphicsRow[RandomChoice[Array[Dice, {6}], {2}]];
prob = Probability[Dice~DiscreteUniformDistribution[{1, 6}]]

RollDice[n_] := Table[Dice[], {n}]
RollDice[9]

The probability for a single roll of n dice should be P = (1/s)^n where s = the sides of the die and n = the number of die available. Therefore the number should always stay the same (1/6), but n must be updated. So I was thinking Prob = (1/6)^Dice[]...

EDIT: I seem to be getting an error when I run the code. It prints "Dice(n_Integer(k))" instead of printing the row of dice needed. Can anyone tell me how to improve here?

EDIT #2: After inputting the built-in probability function, I seem to be getting an error where the code prints out {Dice{}...Dice{}} for an n amount of dice when I need the dice and the probability value of that particular roll.

$\endgroup$
2
  • 1
    $\begingroup$ Probability [Dice~DiscreteUniformDistribution[{1, 6}]]` is wrong syntax. As well as Table[Dice[], {n}] $\endgroup$ Jan 14, 2022 at 21:06
  • $\begingroup$ Thank you. I'll circle back to the documentation when I get a chance. I am trying to learn after all. $\endgroup$ Jan 14, 2022 at 22:09

1 Answer 1

2
$\begingroup$

Using your definition of Dice, woudl this work?

ClearAll[RollDice]
RollDice[n_Integer] := {
   1/6^n,
   Multicolumn[
     Dice /@ RandomVariate[DiscreteUniformDistribution[{1, 6}], n]
   ]
 }

RollDice[2]

1/36 probability and two dice

$\endgroup$
1
  • $\begingroup$ It still prints Dice(n_Integer)(k) but it gives me what I need so thank you for this. Edit: Never mind it doesnt. Thank you! Can you tell me what was wrong? $\endgroup$ Jan 14, 2022 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.