Class: Random

Random

A collection of generator functions that yield random values for use in other Structure classes.

Constructor

new Random()

Don't use. All functions in this class are static.

Source:

Methods

(static) choice(choices)

Randomly yield one of the given values.

Parameters:
Name Type Description
choices Array

the values to randomly yield

Source:

(static) duration(options)

Randomly yield an integer suitable for durations values in a Rhythm.

First a random integer value between min and max is calculated, then it's multiplied by the multiplier.

NOTE: Random durations are currently not supported by Harmony.durations or Rhythm.pattern.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
min Number <optional>
1

minimum possible value (inclusive)

max Number <optional>
4

maximum possible value (inclusive)

multiplier Number <optional>
1

scales the random value

Source:

(static) intensity(options)

Randomly yield a floating point number suitable for intensity values in a Rhythm.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
min Number <optional>
0

minimum possible value (inclusive)

max Number <optional>
1

maximum possible value (exclusive)

Source:

(static) pitch(options)

Randomly yield an integer suitable for relative pitches in a Part.

The default min and max work well with 3-note chords when the part's mode is arpeggio.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
min Number <optional>
0

minimum possible value (inclusive)

max Number <optional>
2

maximum possible value (inclusive)

Source:

(static) weightedChoice(choices, weights)

Randomly yield one of the given values with a probability distribution determined by the given weights.

Parameters:
Name Type Description
choices Array

the values to randomly yield

weights Array

the relative weights for the corresponding values.

Source:
Example
weightedChoice([10,20,30], [1,2,1])
// 10 is yielded 25% of the time
// 20 is yielded 50% of the time
// 30 is yielded 25% of the time