Rolling two dice with user defined functions

2 views (last 30 days)
Keller
Keller on 8 Apr 2014
Commented: dpb on 8 Apr 2014
Hey Everyone! I am looking to get some help with an assignment that I can not seem to figure out. We are supposed to create two user defined functions to simulate two dice being rolled 300 times. For my first function i currently have:
function [s_out] = KJL_roll(s_in)
s_out = floor(6*rand(1)+1);
end
which simulates a single dice being rolled. We are supposed to take that function and use it to simulate two dice being rolled. This is where I am stuck because I have created a way to do it that looks like this:
function [s_out] = KJL_rolls(s_in)
s_out_1 = KJL_roll;
s_out_2 = KJL_roll;
s_out = s_out_1 + s_out_2;
end
Is there a better way to do this using a loop statement? And how would I go about making this run 300 times while counting how many 8s appear during the runs?
Thanks in advance!
  1 Comment
dpb
dpb on 8 Apr 2014
Being as how it's HW, I'll ask some leading questions in return rather than posting direct solution(s)--
A) consider doc randi
B) what's the problem you see in wrapping the above in a counted for...end loop, specifically?
C) outside that what if you were to return more than one value per call? Can you see how that might lead to a useful end?
D) doc hist % and friends

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!