JMAC Docs

JMAC / docs / Random

Random()Method : JMath

Generates a pseudo-random number between a minimum and maximum value


Values

function Random(min?: Number, max?: Number, decimals?: boolean): Number|float

Parameters

min
The minimum value of the generated output.
Defaults to 0.
max
The maximum value of the generated output.
Defaults to 9.
decimals
Determines whether or not the method can return a float.
Defaults to false.

Returns

Number
A pseudo-random integer between min and max.
float
A pseudo-random float between min and max. Only possible when decimals is true.

Common Errors

Error: Invalid return value
Often occurs when min or max has been passed a float, which can sometimes cause the return value to exceed max.

Example


console.log(JMath.Random(4, 39));

// Could return:

23


console.log(JMath.Random(5, 10, true));

// Could return:

7.66666666


Log

JMAC c | 22-05-25

Method introduced.

JMAC g_a | 02-07-25

Method converted to Cast structure as test phase.

JMAC 1a | 02-09-25

Method reverted to normal structure.

Error fixes.