You can add a script to your exercise to define random variables. Use these variables in the instructions and interactions of your exercise.

A basic randomised algebra interaction

This question is the randomised variant of this static algebra interaction. Create a copy of this basic exercise and use the below instructions to update the interaction to make it randomised.

Use the dropdown on the top left to add a script to the exercise.

We will create a script that defines a quadratic equation with integer solutions.

The scripting functionality of AlgebraKiT supports a rich set of commands and programming features. For now, the most important thing is that we have defined the variable expr that represents the random quadratic expression.

In the instruction, change the equation as follows:

In the task definition, update the field for the relation.

Your first randomised exercise is ready! Now click Run.

The following exercise is generated from this example. Refresh the page to see a different instance.

If you want to learn more about scripting then read the section ‘Scripting concepts’ below.

Scripting concepts

Variable definitions

A variable is a sequence of symbols. Allowed symbols are letters, digits, and the underscore. The first symbol must be a letter.

You can create a definition using the symbol :=.

my_variable:= 2x^2-3x+4

Note that the definition does not have to be a number, but can be any mathematical expression.


The following table lists the basic math operators

*Multiplication. See remark 1)
=, >, <, >=, <=, <>Relational symbols (not evaluated)
==, >>, <<, >>=, <<=, <<>>Relational symbols (evaluated, see remark 2)
  1. The multiplication symbol is optional. So 3x is interpreted as 3*x. However, ab is interpreted as the variable ‘ab’ and not as a*b. You should add a times symbol or an extra space if you intend the multiplication.
  2. The relational symbols =, >, <, <=, and >= are used to construct mathematical relations without evaluating them. E.g. x^2=2x is an equation, whereas 2==3 is an expression that will be evaluated as False.


True, FalseBoolean constants
PiThe number π
EulerEEuler’s constant e
{}The empty set


The scripting language of AlgebraKiT defines the following constructions to build expressions:

( )Parenthesis
[ ]Function arguments
{ }List
` `Toggle between text (HTML) and math
[[ ]]List index

Some examples:

Sin[2 x]The sine of 2x
v:= {1, 2a, x^y}Define variable v as a list of 3 items
v[[2]]Take the 2nd element of the list (which is 2a in this case).
Note that the first element has index 1, not 0.
Text[`this is a text`]A command that contains text

Some essential commands

The complete list of commands can be found in the Syntax guide. The following table lists the commands that are used most often.

SimplifyApply mathematical rules to simplify the expression as much as possible.
Simplify[1*x*x] gives x^2
RandomIntGenerate a random integer number within a range.RandomInt[2,10] gives an integer number in the range 2 to 10.
RandSelectSelect a random element from the listRandSelect[{1,x,2y}] gives one of the three items in the list.
StrictEvaluate a boolean expression. An undetermined expression will result in FalseStrict[3>>2] gives True
Strict[x>>y] gives False

Was this helpful?

0 / 0

Was this helpful?

0 / 0