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
| Parameter | Type | Description |
|---|---|---|
max | number | Upper 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
| Parameter | Type | Description |
|---|---|---|
min | number | Lower bound, inclusive. |
max | number | Upper 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
| Parameter | Type | Description |
|---|---|---|
choices | readonly T[] | Values to choose from. |
Returns
T | undefined
A random array element, or undefined when the array is empty.