Is there a way to check answers using rand in MATLAB Grader?
Show older comments
I am using MATLAB Grader to check students' work. Many basic problems ask them to create particular arrays using rand or randi. Is there a way to check if their answer is a possible correct answer?
For example, a problem could ask them to generate a vector v1 of 20 random integers between -4 and 2.
v1 = randi([-4,2],1, 20);
But if I use the assessVariableEqual function to check their answer, it won't work because their answer contains randomized values. I'd like to be able to check the min, max, and length of the result to see that it is within the expected range. Is there a way to do that?
4 Comments
Dyuman Joshi
on 3 Nov 2023
How about asking students to use their roll-number as a seed for rng and checking the values correspondingly.
Though that might defeat the pupose of the use of randi().
Sunil
on 5 Jul 2024
You can fix the seed for the random number generator. The numbers generated will be the same if you use the same seed.
Cris LaPierre
on 6 Jul 2024
See the accepted answer for a better solution.
Patrick Tomassi
on 22 Aug 2024
Edited: Patrick Tomassi
on 22 Aug 2024
Accepted Answer
More Answers (0)
Categories
Find more on Use Content in an LMS Course 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!