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
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.
% 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.
0 · ·