How to use the Random Function of the Scientific Calculator

As seen in a previous post, the new online scientific calculator now has a random generator function. This article describes the new function in detail and how to use it for generating random integers within a specified interval or for simulating random events such as the rolling of a dice.

Random integer function on the scientific calculator

Using the Random Integer Function on the Scientific Calculator

True Random Numbers vs. Pseudo-random numbers

An important aspect of random numbers is that they cannot be generated with computers. A true random number can only be generated by converting the outcome of an unpredictable natural phenomena into numeric form. For example throwing dice or measuring atmospheric noise. The numbers generated by the random number generators in calculators or computer programs are not true random numbers, they are pseudo random numbers.

A pseudo random number is generated using a mathematical formula that, given an input parameter, outputs a number within a specified range. The first time the random funciton is used, a value called ‘seed’ is passed to the function. The output of the previous call is passed as a parameter the second time the function is called and so on. This emulates a random sequence in that, if we don’t know the value of the seed, we cannot predict the number that the function will produce at the next iteration. In computers, usually, the seed is taken from the computer system time. In handheld calculators it can be set manually by the user. The drawback of using a formula is that, depending on how good is the formula, the sequence of numbers will eventually repeat, therefore generating predictable numbers from that point.

The Online Scientific Calculator rand() Function

The rand() function used by the new online scientific calculator is a pseudo-random number generator. It produces pseudo random numbers between 0 and 1.

Generating integer random numbers

Suppose we want to emulate the process of throwing a dice. The dice has 6 faces with numbers from 1 to 6. How can we use the random number function for generating a random integer between 1 and 6?

We need to translate the output (0 to 1) of the rand() function to a number between 1 and 6. This is very easily accomplished:

The total number of possibile outputs is 6 (1, 2, 3, 4, 5 or 6).

If we multiply the result of the rand() function by 5 and round the result, we obtain a random number between 0 and 5.

To change the value between 0 and 5 to a value between 1 and 6 we need to add 1 to the result.

So we can create a function like this: diceroll(f)=round(rand()*(f-1))+1 .

A more generic function to produce random integers between x and y is randint(x,y)=(round(rand()*(y-x)))+x (x represents the minimum and y the maximum integer value).

Generating Random Integers on Scientific Calculators

Of course this same method for generating integer random numbers can be applied with any calculator that has a random function button that returns a number between 0 and 1. On the HP 30S, for example, the button is labeled ‘RANDM’, below you can find a table that shows how to call the random function of a few commonly used calculators:

HP 9S 2ndF + RND
HP 30S RANDM This calculator also features a RANDMI button for generating integer numbers
TI-34 II Explorer Plus RAND RANDI for generating integer numbers
Sharp EL-W531 2ndF+RANDOM

Tags: , , , , , , , , ,

Comments are closed.