problem with the check program like filling the array with random numbers

problem with the check program like filling the array with random numbers

by Алексей Шалфеев -
Number of replies: 1

Hello friends, I'm just starting to learn this wonderful plugin and faced with a problem.

pascal program - filling the array with random numbers, finding the number and sum of the array elements. Can i do thomething with this? 

Program m1;
var a: array [1..30] of integer;
i,s, k:integer;
for i:=1 to 20 do
write (a[i], ' ');
writeln ('s = ', s);
writeln ('k = ', k);
Сan I include the value generated by the user code in the Expected field?
In reply to Алексей Шалфеев

Re: problem with the check program like filling the array with random numbers

by Richard Lobb -

By "User" do you mean the student or the author? The "Expected" field of a test is used to grade the student's code so it doesn't make sense to set it from the student's code. You can set it from the question author's code using the '<<' button in your example above, but that's not helpful in that particular example because the code is randomised.

What exactly are you asking the students to write? If, say, you're asking them to print 20 random integers in [0, 20)  followed by their sum and the count (always 20?), then you have to decide exactly what you will accept. Are you happy if the code prints the sequence 0 .. 19? How about if it prints the value 1 20 times? Both of those outcomes could occur at random but are most unlikely. But then so is the particular sequence generated by your sample program above.

While you might be able to write a complex grader (see "Template graders" in the documentation) to compute the probability that the student's output came from the random number generator, I'd recommend you instead try to ask the question in such a way that the output is deterministic. For example, if you can access the random number seed in Pascal you could ask students to write a function that takes the seed value, plus an integer n as parameters, sets the seed to the given value and prints n random numbers in the range [0, 20) plus their sum.

But it might be worth asking yourself exactly what skill you're trying to test? Do you want to know if students know how to call random? Or if they can fill an array with a sequence of integers provided by some function? Or if they can compute the sum of the elements of an array? The above example doesn't quite achieve any of those (e.g. the code could be written without using an array at all).