Dice Simulation in MatLab

I have to write a script that uses the user input to roll a certain amount of dice, with a certain amount of sides, with a certain amount of rolls , and a certain amount of trials.

I have the whole user input part down, but I'm having trouble writing a function for rolling the dice.

function [ X ] = Dice( N, S, T, R )
% Dice simulates a random selection of numbers which is similar to how a dice is rolled
% N is the number of dice the user wants to roll
% S is the number of sides on the dice
% T is the number of trials that the user wants to run.
% R is the number of rolls that the user wants to roll each dice.

D =ceil(S*rand(1,N))

% I used this for one roll of the dice

Counts = hist(D,[1:S]);

% Then I used this to count how many of each number showed up

How do I write the code so that I can factor in the amount of trials and rolls? I know I probably have to do something with for loops, but I'm very confused and I can't think of anything at the moment.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!