**Description**

Return two random integers between 1 and 6, inclusive, to simulate rolling 2 dice.

**Example**

[x1,x2] = rollDice(); x1 = 5; x2 = 2;

Show
2 older comments

Sourav Mondal
on 20 Nov 2012

is the solution correct???

Jonathan
on 19 Nov 2014

To clarify the problem statement, it would be good to specify the dice are fair.

Dale Crawford
on 7 Dec 2015

I've done something like this on an arduino for one of my classes

John D'Errico
on 23 Aug 2016

The first test case for this problem is flat out statistically terrible! In fact, it is quite easy for that assertion to fail on a well defined set of uniform dice! So if you submitted a "valid" solution to this trivial problem, and it failed, then re-submit it. It may well succeed the second time you try, with no change to your function at all.

Alexander Kramlich
on 14 Sep 2016

Use randi function instead of rand.

2 Comments

niko_k
on 27 Aug 2013

solution is correct in my opinion.

Tim
on 27 Aug 2013

rand(1,1)*5+1 will produce random numbers uniformly distributed between 1 and 6; round will convert values from 1 to 1.5 to 1, and values from 1.5 to 2.5 to 2, so 1 will occur only about half as often as 2. Overall, 1 and 6 will occur only about half as often as 2, 3, 4, and 5.

1 player likes this solution

1 Comment

Paul Peeling
on 23 Nov 2012

my second ever pseudo random number generator (the first wasn't very random) http://en.wikipedia.org/wiki/Linear_congruential_generator

2 Comments

Peter Wittenberg
on 11 Aug 2012

This is not two random rolls. The second number will never match the first, so the statistical distribution is not correct, although the test suite is not sophisticated enough to catch it.

Matthew M.
on 28 Aug 2012

^Agreed.

1 Comment

Kye Taylor
on 31 Mar 2012

Super rad test suite

1 Comment

Giuseppe Cardillo
on 20 Feb 2012

THIS SOLUTION IS CORRECT!!!!!

2 players like this solution

1 Comment

Santiago Velasco-Forero
on 2 Aug 2012

False solution.

**Tags**

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
10 players like this problem

10 players like this problem