## Define random variables and functions

The *Define random variables and functions* section is at the core of many of Wiris Quizzes' capabilities. We define variables here in a computer algebra system (CAS), and these are used in various parts of the question definition, mainly in the question's statement and correct answer. If you're familiar with CalcMe, then you have a head start. If not, it's easy to get started. You can think of it as a big scientific calculator, but it can also manipulate symbolic equations. You can always check CalcMe basic guide.

### Declaring variables

Variables are defined by writing a name for a variable, an equal sign, and an expression on the right-hand side. For example:

There are two details to note:

#### Declaring variables

- The left-hand side can be any letter or word without spaces, excluding reserved words (e.g.
`sin`

,`cos`

) - The right-hand side can be any reasonable mathematical expression, be it numerical (as in the first variable above) or algebraic (as in the second).

Within this field, variables can be manipulated and acted on, and new variables can be defined from old ones, just as on paper. For instance:

#### Algorithm language

The algorithm field is available in multiple languages. By default, the language of the CAS will be the same as Moodle, or English as the fallback. But you can choose another one of the available languages.

If you change the CalcMe language then any existing algorithm in it will be automatically translated. This is very useful if you have algorithms in other languages, like the ones in STEM collection.

### Inserting variables

Those are the basics of how variables function inside of Wiris Quizzes Studio. What's very important though, is to know how to use these variables *outside* of Studio. The answer is simple:

**#**followed by the name of the variable (e.g.

`#a`

)So we could include the above polynomial in a question just like this:

This would appear to the student as:

### Random variables

Perhaps the most important use of variables is to introduce randomness in a question. There is a simple instruction in CalcMe that generates random numbers, `random()`

. For example,

generates a random number between -10 and 10. This could then be used in the question text as we have seen. The result is that each time the question is opened, a random value for `a`

is used. So, students viewing the same question will see potentially different values.

### Output options

Different countries, education levels, or textbooks, use different notations. You can configure some output options in the *Application settings* section inside CalcMe to better match the notation you use.

These options apply only to the values generated in the *Algorithm* field, i.e. the variables. All generated values will be in the same notation; you can not generate values in different notations.

#### Imaginary unit

Choose between `i`

and `j`

(often used in electrical engineering).

#### Times operator

Choose between middle dot `·`

and cross `x`

. Set *Implicit* to hide all non-necessary products, that is, implicit products.

#### Precision

*Precision* must be an integer between 1 and 15 included, and it can be set as *Significant figures* or *Decimal places*. By default it is `Precision = 4 significant figures`

.

All notations usually imply a rounding. When rounding, the rule used for tie-breaking is half-up.

#### Notation

These notations apply only to decimal numbers. Numbers and expressions without a decimal point in them are exact, and so these notations don't apply to them. You can always convert an exact expression to decimal by multiplying by `1.0`

for instance.

#### Decimal

Choose the symbol for the decimal mark. Available options depend on the symbols in *Validation* tab, in *Options... > Separators* marked as *Decimal digits*. Trailing decimal points of integer numbers are never shown.

#### Thousands

Choose the symbol for the digit groups separator, that is, thousands separator.
Available options depend on the symbols in *Validation* tab, in *Options... > Separators* marked as *Digit groups*.

#### List items

Choose the symbol for the list items separator. Available options depend on the symbols in *Validation* tab, in *Options... > Separators* marked as *List items*.