Step 8: Using randomisation
Now we will create a question that uses randomisation. We will copy the first_question_with_variables.yaml
file to first_question_with_randomisation.yaml
and change the value of variable a
to random(1..10)
. This will choose a random integer between 1 and 10 as value for a
.
---
type: normal
statement: How much is 9 * {a}?
advice: You could calculate 10 * {a} and then subtract {a}. This yields {a} * 10 - {a} = {a * 10} - {a} = {a*9}
parts:
- type: number_entry
prompt: Enter your answer in the inputbox
marks: 5
answer: a * 9
show_correct_answer: true
show_feedback_icon: true
display_correct_as_fraction: false
allow_fractions: false
fractions_must_be_reduced: false
fractions_must_be_reduced_hint: false
partial_credit_if_fraction_not_reduced: 0
display_correct_in_style: &style english-plain
allowed_notation_styles:
- *style
custom_marking: none
steps: []
steps_penalty: 0
adaptive_marking: none
part_name: none
variables:
a: random(1..10) # this changed
# All fields below are not imporant yet, but need to be specified. Rumbas doesn't use any internal default values.
builtin_constants: # all constants will be disabled
e: false
pi: false
i: false
custom_constants: []
grouped_variables: none
variables_test:
condition: ""
max_runs: 1
functions: {}
preamble:
css: ""
js: ""
navigation:
can_regenerate: false
show_title_page: false
confirm_when_leaving: false
extensions:
jsx_graph: false
stats: false
geogebra: false
eukleides: false
chemistry: false
download_text_file: false
graphs: false
linear_algebra: false
linear_codes: false
optimisation: false
permutations: false
polynomials: false
quantities: false
random_person: false
written_number: false
sqlite: false
text: false
diagnostic_topic_names: []
resources: []
custom_part_types: []
rulesets: {}
Copy the first_question_with_variables.yaml
file to first_question_with_randomisation.yaml
and change the definition of the variables a
as indicated in the file above.
Now we will create a new exam that uses this question. We will copy the first_exam_with_variables.yaml
file to first_exam_with_randomisation.yaml
and add the new question to the questions
field.
---
type: normal
name: First Exam
question_groups:
- name: Group 1
picking_strategy:
type: all_ordered
questions:
- first_question.yaml
- first_question_with_variables.yaml
- first_question_with_randomisation.yaml # We added this
navigation:
mode: sequential
start_password: none
can_regenerate: true
show_steps: false
show_title_page: false
confirm_when_leaving: false
show_names_of_question_groups: true
allow_printing: false
can_move_to_previous: true
browsing_enabled: true
show_results_page: never
on_leave:
action: none
feedback:
percentage_needed_to_pass: 50
show_name_of_student: false
show_current_marks: true
show_maximum_marks: true
show_answer_state: true
allow_reveal_answer: true
review:
show_score: true
show_feedback: true
show_expected_answer: true
show_advice: true
advice: "Please practice more"
intro: "An introductory text"
feedback_messages: []
timing:
duration_in_seconds: none
allow_pause: true
on_timeout:
action: none
timed_warning:
action: none
locales:
- name: en
numbas_locale: en-GB
numbas_settings:
theme: default
Copy the first_exam_with_variables.yaml
file to first_exam_with_randomisation.yaml
and add the question as indicated in the file above.
We can then compile all exams with the following command:
rumbas compile exams
And open the new exam in the browser by browsing to http://localhost:8000/en/exams/first_exam_with_randomisation/
.
Also try the following things for the third question:
- Reload the page and use the
Reveal answers
button to see the correct answer. You will see that the calculations in themarks
andadvice
fields are calculated. - Try the
Try another question like this one
button.- For the third question, this will generate a new question with a new value for
a
. - You will see that after trying another question and using the 'Reveal answers' button, the advice is changed to use the new value of
a
.
- For the third question, this will generate a new question with a new value for
You can also find the exam in the online demo.