Try now in the
Open Cloud »
(no sign-in required)

Random Melodies

Play random melodies with various scales and instruments.

Run the code to play a musical note. Try note numbers other than 0:

SHOW/HIDE DETAILS

SoundNote denotes a musical note. Pitch 0 is middle C:

In[1]:=
X

SoundNote by itself doesnt make a sound. Put it inside Sound to make a playable note (click the Play button to play the note):

In[2]:=
X
Out[2]=

Play the note immediately with EmitSound:

In[3]:=
X

HIDE DETAILS
In[1]:=
X

Play a sequence of notes. Try other sequences:

SHOW/HIDE DETAILS

To play a sequence of notes, put the notes in a list (indicated by the curly braces):

In[1]:=
X

This is how the note numbers correspond to piano keys:

Out[1]=

Lower notes have negative numbers. Note numbers can range from -60 to 67:

In[2]:=
X

HIDE DETAILS
In[1]:=
X

Play the notes faster. Try other durations:

SHOW/HIDE DETAILS

Unless you indicate otherwise, each note is played for 1 second:

In[1]:=
X

To play notes faster or slower, specify the length of the entire sequence in seconds:

In[2]:=
X

HIDE DETAILS
In[1]:=
X

Play a random 8-note melody. Try other lengths of melodies:

Hint: run the code again to get a different melody.

SHOW/HIDE DETAILS

Get a random number between 1 and 12. Each time you run the code, a different number is chosen:

In[1]:=
X
Out[1]=

Play a random note. Each time you run the code, a different note is played:

In[2]:=
X

Make a list of 8 random notes:

In[3]:=
X
Out[3]=

Play 8 random notes for a duration of 2 seconds:

In[4]:=
X

HIDE DETAILS
In[1]:=
X

Play a random melody from a scale. Try different scales:

SHOW/HIDE DETAILS

The black notes on the piano form a pentatonic scale:

Out[1]=

This chooses a random note from a pentatonic scale:

In[1]:=
X
Out[1]=

Play 8 random pentatonic notes:

In[2]:=
X

You can also use note names to specify the notes:

In[3]:=
X

Play 8 random notes from a C-major chord. The C above middle C is called c5. Another name for c is c4:

In[4]:=
X

HIDE DETAILS
In[1]:=
X

Play a random melody on random instruments. Try other instruments, like Oboe, Glockenspiel, or HonkyTonkPiano:

SHOW/HIDE DETAILS

Play a note with a xylophone sound (the second value, 1, is the notes duration):

In[1]:=
X

Play a note with a clarinet sound:

In[2]:=
X

Play a note with a xylophone, clarinet, or violin sound chosen at random:

In[3]:=
X

Play 8 random notes with random instruments:

In[4]:=
X

Heres a list of the available instruments:

Out[4]=

HIDE DETAILS
In[1]:=
X