Namespace: Random:randomNumber

Random:randomNumber

Source:

Methods

randomNumber(flooropt, nullable, ceilingopt, nullable, floatopt, nullable, precisionopt, nullable) → {Number}

Special form of Math.random, returning a value in a defined range, where floor and ceiling are included in the range.

By default, this method return an integer, but by setting "float" to true and optionally providing a float precision you can also work with floating point numbers.

Parameters:
Name Type Attributes Default Description
floor Number <optional>
<nullable>
0

the lower end of random range, can either be integer or float

ceiling Number <optional>
<nullable>
10

the upper end of random range, can either be integer or float

float Boolean <optional>
<nullable>
false

define if we are working with floating point numbers

precision Number <optional>
<nullable>
2

if we are working with floats, what precision are we working with, considering floor, ceiling and result?

Source:
Throws:

error if ceiling is smaller than floor

Returns:
random integer or float between floor and ceiling
Type
Number
Example
let randomInt = randomNumber(23, 42);
let randomFloat = randomNumber(23.5, 42.123, true, 3);