Random

Make a random number, integer, boolean, string, colour or choice on each trigger; seeded when a seed is wired.

  • Data
  • Since 0.2.0
  • random
  • noise
  • chance
  • colour
  • choice
  • seed
  • data

Open in TuneToys

Random as the Patch draws it, at default values: inlets on the left, outlets on the right.

Random makes a new value each time its trigger input fires: a number, a whole number, true or false, a string, a colour or one of your own choices.

What it does#

Type chooses the datatype on value. Number and Integer fall between Minimum and Maximum, Boolean is true or false, String is Length characters from the node's alphabet, Colour is #rrggbb text and Choice picks one of the node's listed strings.

Without a seed cable each draw is unpredictable. With a seed cabled in, the sequence is a function of the seed and the draw count, so the same seed gives the same values every time the Toy starts.

During replay Random does not draw again: the values it sent while the take was recorded are played back.

When to use it#

Use it with Cron for generative patterns, to colour an led lamp, or, through Data to control, to move a parameter by chance.

Ports#

PortDirectionSignalLanes
triggerInputData (trigger)1
seedInputData (integer)1
valueOutputData (any)1

Parameters#

ParameterLabelRangeDefaultUnitScaleNotes
typeType0 to 50linearDatatype of the value; Choice picks one of the listed strings. Choices: 0 Number, 1 Integer, 2 Boolean, 3 String, 4 Colour, 5 Choice.
minMinimum-1000000 to 10000000linearSmallest number or integer.
maxMaximum-1000000 to 10000001linearLargest number or integer.
lengthLength1 to 648linearCharacters in a random string.
distributionDistribution0 to 10linearUniform spreads values evenly; Normal clusters them around the middle of the range. Choices: 0 Uniform, 1 Normal.
  • alphabet: text.
  • choices: strings.

Type (type)#

Number, Integer, Boolean, String, Colour or Choice. The value port takes this datatype, so a cable from it must fit: a colour feeds a lamp, a number feeds Data to control.

Minimum (min) and Maximum (max)#

The range for Number and Integer, from -1 000 000 to 1 000 000.

Length (length)#

Characters in a String, 1 to 64, drawn from the node's alphabet text field (letters and digits when empty).

Distribution (distribution)#

Uniform spreads values evenly across the range. Normal clusters them around the middle, which makes a random walk feel calmer.

Choices and alphabet#

The choices field lists up to 64 strings for Choice; the alphabet field sets the characters for String. Both are edited in the inspector.

Tips#

  • Set Minimum and Maximum equal to send a constant number on every trigger.
  • Wire a Value through Convert into seed for repeatable patterns.

See also#

Cron, Data to control, Merge, Data cables.

Help patches

Each help patch is an ordinary Toy that teaches one idea. The diagram shows the Patch; the preview shows its Frame. Open it in TuneToys to play and edit it.

1. Colours and numbers

beginner Teaches: type, min, max

One Random node picks a colour for a lamp; another picks a number that moves a filter.

Patch: Oscillator audio output connected to Filter audio input. Filter audio output connected to Patch outputs audio input. Data to control control output connected to Filter @cutoff input. Cron tick output connected to Random “colour” trigger input. Cron tick output connected to Random “amount” trigger input. Random “amount” value output connected to Data to control value input.
Connections as text
  • Oscillator audio output connected to Filter audio input
  • Filter audio output connected to Patch outputs audio input
  • Data to control control output connected to Filter @cutoff input
  • Cron tick output connected to Random “colour” trigger input
  • Cron tick output connected to Random “amount” trigger input
  • Random “amount” value output connected to Data to control value input
  • Type Colour sends #rrggbb text; Type Number sends a number between Minimum and Maximum.
  • Data to control maps 0–1 onto the cutoff lane.
Frame preview: Colours and numbersFrame “Colours and numbers” with 3 elements: text heading, text hint, led Lamp.COLOURS AND NUMBERSPress Play. Twice a second the lamp changes colour and the filter jumps to a ne…led
Frame preview (static). Controls show their default values.

Open in TuneToys

2. Seeded choices

intermediate Teaches: length, distribution

A wired seed makes Random repeat the same sequence of choices every time the Toy starts.

Patch: Cron tick output connected to Random trigger input. Value value output connected to Convert value input. Random value output connected to Console log value input. Convert value output connected to Random seed input.
Connections as text
  • Cron tick output connected to Random trigger input
  • Value value output connected to Convert value input
  • Random value output connected to Console log value input
  • Convert value output connected to Random seed input
  • Choice picks one of the listed strings; String would use Length characters from the alphabet.
  • A cabled seed makes the sequence a function of seed and count.
Frame preview: Seeded choicesFrame “Seeded choices” with 2 elements: text heading, text hint.SEEDED CHOICESPress Play and open the Console. Restart: the same syllables come back in the s…
Frame preview (static). Controls show their default values.

Open in TuneToys

  • Cron Fire a trigger on an interval, a cron expression or musical beats, with the time as JSON.
  • Data to control Turn numbers into one control lane for a parameter or control input, mapped from a declared range.
  • Merge Combine up to eight inputs into one JSON object keyed by port, when any or all have arrived.

Edit this page on GitHub

esc

↑ ↓ move↩ open⌘↩ new tabesc close