# Random sound

**URL:** <https://forum.kirupa.com/t/random-sound/5440>\
**Category:** Uncategorized\
**Created:** [September 11, 2002, 2:34pm UTC](https://forum.kirupa.com/t/random-sound/5440 "2002-09-11T14:34:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tham007](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@tham007](https://forum.kirupa.com/u/tham007)\
**Post date:** [September 11, 2002, 2:34pm UTC](https://forum.kirupa.com/t/random-sound/5440/1 "2002-09-11T14:34:11Z")

</div>

I’m a beginner and I’m trying to make a button playing sound randomly each time you press it :  
I’ve imported 10 sounds, and i want to play randomly 1 sound from 5 sounds I define from the 10 of the library…each time i press on the button.

pleeeeeeeeaaaz help !☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 11, 2002, 2:52pm UTC](https://forum.kirupa.com/t/random-sound/5440/2 "2002-09-11T14:52:09Z")

</div>

It’s me again 😉

I’ve try that for only 2 sounds and it looks like it works!

on (release) {  
if (random (2)\<1) {  
son2.stop();  
} else {  
son2.start(0,1 );  
}  
}

it’s my first try so please understand my …weakness on this and be sure i’m open to any advice!!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 19, 2002, 12:46pm UTC](https://forum.kirupa.com/t/random-sound/5440/3 "2002-09-19T12:46:09Z")

</div>

You might like to try …

Export your 10 sounds with the linkage:  
s11, s12, s13, … s20

When you want a sound use

randomSound=new Sound();  
randomSound.attachSound(“s”.concat(Math.floor(Math.random()\*10)+10));  
randomSound.Start();

or, if you want to give your sounds descriptive names …

Export your 10 sounds with the linkage:  
ding, ping, crash …

When you want a sound use

soundList= new Array (“ding”,“ping”,“crash”, “boom”)  
randomSound=new Sound ()  
randomSound.attachSound(soundList[Math.floor(Math.random()\*soundList.length)])  
randomSound.Start()
