Random background music

how to write a code that play background music randomly?

i write these in the frame
bgmusic = new Sound();
bgmusic.loadSound(“1.mp3”, true);

in the movie
there are buttons with action
on (release) {
bgmusic.loadSound(“1.mp3”, true);
}

//there are some buttons with 1, 2, …mp3 respectively, also null for stop…

then how to make it play background music randomly within 1, 2, 3.mp3?

bgmusic.loadSound(Math.ceil(Math.random()*3)+".mp3", true);

=)

thank you very much

no problem. :wink:

Can you explain to me what Math.ceil means?

thanks
-brian2

Returns the closest integer that is greater than or equal to the number returned by Math.random()*3.

Examples:
Math.random()*3 returns 0.254530019871891, Math.ceil rounds it to 1.
Math.random()*3 returns 1.808154902886599, Math.ceil rounds it to 2.
Math.random()*3 returns 2.119892139919164, Math.ceil rounds it to 3.

Got it? =)