Asked by Hannah Bartolo
on 12 Jul 2018

Given, a two six-sided dice are rolled and the two numbers showing are added to produce a sum between 2 and 12.

Answer by Adam Danz
on 13 Jul 2018

To simulate a roll of a n-sided die, use the randi() function. You can generate two random integers between 1 and 6 (inclusive) with one function call.

Then all you need to do is use sum() on the results of randi(). This assumes the dice are fair.

You could do this in one line if you'd like

sum(randi()); %you fill in the parameters of randi

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 3 Comments

## Bob Nbob (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/410132-how-would-i-create-a-plot-showing-each-event-on-the-x-axis-and-p-x-the-probability-of-each-event#comment_588778

## Adam Danz (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/410132-how-would-i-create-a-plot-showing-each-event-on-the-x-axis-and-p-x-the-probability-of-each-event#comment_588833

## Hannah Bartolo (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/410132-how-would-i-create-a-plot-showing-each-event-on-the-x-axis-and-p-x-the-probability-of-each-event#comment_588835

Sign in to comment.