Dice Simulation in MatLab - Programmers Heaven

Howdy, Stranger!

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


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Dice Simulation in MatLab

amanda7106amanda7106 Posts: 2Member
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.