Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We have seen that we can generate a random number in the range [1, 6] to represe

ID: 3601658 • Letter: W

Question

We have seen that we can generate a random number in the range [1, 6] to represent the roll of a six sided die, by using: randi( [1, 6], 1 ) Modify the Function file so that it:

(a) Takes three such die values as input

(b) Determines if those three die values constitute a Straight - they can be arranged to form a sequence of consecutive values

(c) Returns true if they constitute a Straight, and false if not.

. Create a Function file named Lab07

(a) Right click Current Folder title of that window

(b) Select New File by moving mouse to that option

(c) Click on Script in the pop-up menu

(d) Type Driver07 in the highlight field and hit the enter key

. Double click the Driver07.m entry (that you just created) in the Current Folder window Modify the Script file so that it:

(a) Generates three random ”die” values

(b) Determines if those three die values constitute a Straight by call your function Lab07

(c) Displays the generated die values and the functions output in a reasonable report like format

Explanation / Answer

%Use this function to check if the numbers are a Straight(copy code below and save the function)

function randi = randiConsecutive(n1, n2, n3)
if(n2=n1+1)
if(n3=n2+1)
  return true;
end
else
if(n1=n2+1)
if(n3=n1+1)
  return true;
end
else
if(n3=n1+1)
if(n1=n2+1)
  return true;
end
else return false;
end


%Now, use the randi function three times , to have three random die values (copy the code below and run it)

x= randi([1,6],1)
y= randi([1,6],1)
z= randi([1,6],1)

%Now call our function randiConsecutive
randiConsecutive(x,y,z)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote