Skip to content

textmode.js / Textmodifier / random

Method: random()

Call Signature

ts
random(): number;

Return a random number from 0 up to, but not including, 1.

When the sketch is created with seed, or after calling randomSeed, this method returns a reproducible sequence. This pseudo-random generator is intended for creative coding and is not cryptographically secure.

Returns

number

Random number in the range [0, 1).

Example

Call Signature

ts
random(max): number;

Return a random number from 0 up to, but not including, max.

Parameters

ParameterTypeDescription
maxnumberUpper bound, exclusive.

Returns

number

Random number in the range [0, max).

Example

Call Signature

ts
random(min, max): number;

Return a random number from min up to, but not including, max.

Parameters

ParameterTypeDescription
minnumberLower bound, inclusive.
maxnumberUpper bound, exclusive.

Returns

number

Random number in the range [min, max).

Example

Call Signature

ts
random<T>(choices): T | undefined;

Return a random element from an array.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
choicesreadonly T[]Values to choose from.

Returns

T | undefined

A random array element, or undefined when the array is empty.

Example