Random Number Generation

Simple random function – r()

One typical use of OTTER’s interpreter is to generate a random number that fits certain constraints. The first such function available is the r() function. This function chooses a random number from a sequence of numbers that are specified using a starting point, an endpoint, and a step (increment). The syntax is shown below.

image-1635324164257.png

Example

image-1635324355552.png

Complex random function – rf()

There is another function that allows one to generate a random number: rf() It is like the previous function r() but accepts one extra parameter – a function that generates a sequence from which a number will randomly be chosen. It can be useful, for example, if you want the random number to be a square number for example or a cube. 

image-1635325020445.png

Exampleimage-1635325100129.png