Problem 174. Roll the Dice!
Solution Stats
Problem Comments

18 Comments
is the solution correct???
To clarify the problem statement, it would be good to specify the dice are fair.
I've done something like this on an arduino for one of my classes
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 resubmit it. It may well succeed the second time you try, with no change to your function at all.
Use randi function instead of rand.
Rigorous testing of RNG's is a challenging topic. See e.g. https://en.wikipedia.org/wiki/Diehard_tests and https://en.wikipedia.org/wiki/TestU01 .
why can't use unidrnd(6)?
Anyone want to tell me the odds of correctly completing the problem, and then having the checker reject it? Because i have a screenshot of my solution being rejected. Tried exactly the same again and it passed.
@jiangming wang: Cody utilizes vanilla MATLAB (no toolboxes).
Someone please explain me the question
Đề khó hiểu thật !
I offered a solution that should be working (works okay in Matlab) but not here: round(rand()*5+1);  not the most optimum, but still provides the correct output, yet fails the test
can anyone help me why
x1 = 1 + (5)*rand(1,1);
x2 = 1 + (5)*rand(1,1);
is wrong???
It's very easy with function "randi"
Yes, it is better to use randi, instead on rand
rand generates random numbers and randi generates random integers
Very easy
nice!
Solution Comments

1 Comment
fix function is better than round function with regard to this problems

1 Comment
this question is not good , assert judgement not correct on all situations.

1 Comment
@cui, your solution works, not sure why it was not working earlier

2 Comments
good problem
good prob

1 Comment
simple!

1 Comment
I really liked this problem...

1 Comment
a problem with the test suite. Due to the amount of random generation number, the server collapses. It would be nice to reduce 6000 to maybe 100. So that valid solutions (tested in MATLAB desktop) are accepted.

1 Comment
What's wrong with this solution? Can someone tell me?
function [x1,x2] = rollDice()
rng(0,'twister');
r=randperm(6,10)
x1 = r(1)
x2 =r(2)
end

1 Comment
x1=randi(6,1);
x2=randi(6,1);
interesting

1 Comment
Can I get the answer for this question

2 Comments
This failed on first submission, and completed successfully on second. Does this mean the test is nonrobust?
the test case is totally erroneous.

1 Comment
LOL. Just my luck.

2 Comments
solution is correct in my opinion.
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 Comment
my second ever pseudo random number generator (the first wasn't very random) http://en.wikipedia.org/wiki/Linear_congruential_generator

2 Comments
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.
^Agreed.

1 Comment
Super rad test suite

2 Comments
THIS SOLUTION IS CORRECT!!!!!
Not correct. Same coding issue as in Solution 311131.

2 Comments
False solution.
Agreed: this is not a genuine solution, although it does (sometimes) pass the current test as implemented.

1 Comment
Nice! didn't know about that function.
Problem Recent Solvers7845
Suggested Problems

Given two arrays, find the maximum overlap
1087 Solvers

449 Solvers

Back to basics 11  Max Integer
755 Solvers

411 Solvers

625 Solvers
More from this Author56
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!