REF / Music API / Random

Ascene . Agraph . Aengine
Anode . Modulator . Envelope
Songbook . Song . TimeKeeper
Voices . SampleMgr . StreamMgr
Loader . Async . Plot
Random . Rhythm . Util
MIDI . OSC . HID . Piano
Music Theory with Tonal

right-click to navigate to page sections


Random expose a small set of utility functions related to random numbers.

API

These functions reside within the Random namespace.

Function Description
Choose(items) returns a random element from the items array.
ChooseWeighted(items,weights) returns a random element from the items array selected with a probability in proportion to its associated weight. Both arrays must have the same length and weights must be contain numbers.
Draw(items) returns a random element from the items array and removes it from items.
InRange(min, max) returns a random number between min and max distributed uniformly.
ExpInRange(min, max) returns a random number between min and max distributed exponentially. Useful to generate values in perceptual spaces like frequency and ampltitude. Note that min must be greater than 0.
Offset(val, early, late) Returns an offseted value, often either a time or a dur, by a random amount described by two numbers. early (shorten) subtracts from value, late (lengthen) adds. Use this to "humanize" the timing of your notes.
Walk(val, maxStep, minmax?) returns a new value randomly offset from val by maxStep. If minmax[2] is provided, the result will be clamped in that range. Called repeatedly, this results in a random walk.
home .. topics .. interface .. reference .. examples .. tipjar