Hi, i'm using now CodeRunner for two years and i think it's a fabulous work. I don't use it only for testing students programs but also for asking standard questions. Two years ago, i asked if it was possible to define random values in a question. It is now possible with Twig template, but ........ It is really a nightmare to program in Twig and also Twig has a very restrictive set of function. It is enough to generate random values. As an example let suppose that i want to ask the question : What is the inverse of a modulo n, i must generate a random n (easy) and now i must generate an integer a which is co-prime to n, to do that i must compute the gcd of a and n until this value gives 1. Twig has not been designed for this kind of problem. Hence i would like to know if in the future, it will be possible to define random values in a question from a Python code or even from a PHP code , since all coderunner is developped in PHP. As an example the STACK project allows to define random variables by calling some maxima function. It will be really great if CodeRunner could allow this facility.
Sorry Pascal but I don't plan on changing the current randomisation capability. I accept that Twig has its limitations but it's the template language used to expand the question template and all other components of the question including the question text and all test cases (if TwigAll is set).
There are usually ways around the sort of problem you describe. For example:
- Precompute a list of parameter sets (e.g. a, n and the answer b in your example) and pick one at random. Just don't precompute too many possibilities or you'll find Twig bogs down at the start of test, processing the large lists you've given it. For your example question you could precompute a triangle of modular inverses as at https://oeis.org/A102057 and then just generate random row and column indices.
- Generate the question parameters (a and n in your example) and let the grader determine if the answer is right. In a simple case like your example, if the student's answer is b, the grader need check only if (a * b) % n == 1 to determine if the answer is right.
- As an extension of (2), use a template grader so that the Expected column of the result table can be filled in, too.