Randomness

One of the most interesting functions in WIRIS quizzes is the possibility of adding random content.

Moodle already offers some resources in these respects, but limited to choosing a random question among a group of preset questions. WIRIS quizzes permits the integration of randomness at any level, in the question data, in a graph, or in the definition of a mathematical object.

We will see it with an example. We will create a Multiple choice question in which the student will have to factorize a random integer and choose the correct answer among three possibilities.

Steps to follow:

  1. In the Create a new question menu, we must choose True/False. The edition page for this type of question will display.
     
  2. Provide a name for the question in Question name field. 
     
  3. Scroll down to the end of page and click . In this section, a WIRIS cas session will display in the Algorithm field.
     
  4. In the algorithm, we will request a random natural number smaller or equal to 100. For that, we define the algorithm as follows:



    Randomprime and factorize functions are internal functions in WIRIS. Factorization is useful for verification purposes, but can be useful also to send feedback to the student. To keep it simple we will not see it in the current example, but you can go to the page corresponding to this subject in the manual.

    Let us summarize what we did:
    1. We wrote the calculations within the yellow box:



      Remember that only the content of the yellow box is used by Quizzes. The space beside it can be used for checks or auxiliary operations during the edition process.
       
    2. We defined two variables, called n, and sol.
      1. n is the random number.
      2. sol contains the true or false value depending on n value.
         
    3. Use the random function to obtain a random number. This is how questions with random content are created. We must specify that the random function can be used also with elements on a list, where it returns one of these elements by chance. Go to the following chapter, Random content, if you wish to see an example.
       
    4. If you want to make sure there is no mistake, use the key combination Control+Enter or the  button. WIRIS cas will inform of any syntax error by colouring the affected instruction but will not display the result in any of the calculations. Now the cursor is placed outside the yellow box. In order to see the results, we can request the values of the n and sol variables as many times as desired: writing the names of the variables in the block beside the library, comma-separated or split in several lines with the Enter key and, lastly, throwing the calculation with the key combination Control+Enter or the  button.
       
  5. Return to the start of the page and fill in the Question text field:



    Remember that, in order to refer to a previously defined variable in the algorithm, we use the sign right before the name of the variable, with no space between sign and name. This happens for all text or html fields in which variables can appear.
     
  6. Click  to save the question.

    The preview should be similar to the following: