This code uses the Minim library, which makes it possible to play sounds from Processing.
Looking at Minim’s documentation, I found the AudioPlayer#playNote() function, which allows playing of a note at a specific frequency.
Now that we have that function, we can feed it random values to create a random song.
import ddf.minim.Minim;
import ddf.minim.AudioOutput;
AudioOutput out;
void setup() {
size(300, 100);
Minim minim = new Minim(this);
out = minim.getLineOut();
frameRate(4);
}
void draw() {
float note = random(1000);
out.playNote(note);
stroke(random(256), random(256), random(256));
line(width*note/1000, 0, width*note/1000, height);
}
The result is a random “song” that sounds like this:
Oh and then just for fun, I’m drawing a randomly colored line with an X value based on the frequency of the note.

keyPressed() function to turn your keyboard into a synthesizer. Or play a note when the user clicks, based on the mouse position.noise() function instead of playing random notes.