Skip to main content

.rand_int()

A function that returns a random number (integer) between two integer parameters.

Syntax

#fs.scripts.lib().rand_int(min, max, rng);

Parameters

min

The minimum number to generate (inclusive). This minimum number may show up in the returned random number.

max

The maximum number to generate (exclusive). The maximum number the function will generate will be one less than this number.

rng (optional)

A random number generator function. Defaults to Math.random.

Return

Returns a number (integer) between the min (inclusive) and max (exclusive).

Example

This example chooses a number between 0 and 99 and returns it. The function could be used for picking a number for a guessing game.

function(context, args) {
const l = #fs.scripts.lib();
return l.rand_int(0, 100);
}