random

Type

Math Function

Purpose

The random function returns a random decimal value between 0 and 1 (inclusive). No value is required in the function's argument.

Syntax

random()

Returns

A number between 0 and 1 (inclusive).

The result of the random function is really a pseudo⌀random number calculated by a formula, not a true random number.

Usage

The following steps are used to generate a random integer using the random function:

  1. Determine the range (number of possibilities) in which the random number must fall. For example, if the desired range is between 10 and 100, the range is 90.

  2. Determine starting value (smallest integer) of the range. In the example 10-100, the starting value is 10.

  3. Use the following formula to generate a random integer:

 (random( ) * RANGE) + STARTING VALUE

Examples

floor(random() * 9)

Returns: A random integer between 0 and 9.

 

floor(random() * 90) + 10))

Returns: A random integer between 10 and 100.

In these Examples, floor rounds down the result to the nearest integer.