These deterministic random utils made available in the scene cope are primed with the seed value
set in the retrace editor. Thus, using the same seed while using these functions
will produce the same "random" result. Perfect for generative work as you can easily recreate
a generated result.
An instance of simplex-noise.js,
primed with the scene seed, is also available. See example below
Properties:
Name | Type | Description |
---|---|---|
simplex |
Object | The simplex js object |
Methods
(static) maybe(cb, p)
Maybe run a function given a probability value.
Determinstic based on the scenes random seed.
Parameters:
Name | Type | Description |
---|---|---|
cb |
function | The callback to run |
p |
number | Probability that the function will be run (0 - 1). |
(static) pluckRandom(arr) → {any}
Pluck a value from a given array, randomly.
Determinstic based on the scenes random seed.
Parameters:
Name | Type | Description |
---|---|---|
arr |
array | The array |
(static) random(…limit) → {number}
Return a random float value within a given range.
Determinstic based on the scenes random seed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
limit |
number |
<repeatable> |
One argument for a random value in the range [0, limit], two arguments for the range [limit1, limit2]. |
(static) randomBool() → {bool}
Return true or false, randomly.
Determinstic based on the scenes random seed.
(static) randomInt(…limit) → {number}
Return a random integer value within a given range.
Determinstic based on the scenes random seed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
limit |
number |
<repeatable> |
One argument for a random value in the range [0, limit], two arguments for the range [limit1, limit2]. |
(static) randomSign() → {integer}
Return 1 or -1, randomly.
Determinstic based on the scenes random seed.
(static) takeRandom(arr, n) → {any}
Pluck n values from a given array, randomly.
Determinstic based on the scenes random seed.
Parameters:
Name | Type | Description |
---|---|---|
arr |
array | The array |
n |
number | Number of elements |