Sound playing at random. (JS)

Hey, I have a script running certain sounds when I do certain things.Besides that I want to be able to have different Soundclips playing in a random order at random times. (The game we’re making is trying to be creepy so those Soundclips could be things like Screams etc.)

I would preferably want to have that in the same script to make things less complicated. Here’s what I have now:

#pragma strict

var moveSound : AudioClip;
var landSound : AudioClip;
private var hasJustLanded = true;

var controller : CharacterController = GetComponent(CharacterController);     
function Start () {
    audio.clip = moveSound;
function Update()
    var isMoving = Input.GetKey("w") || Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d");
    if (controller.isGrounded) {
       if (isMoving) {
         if (!audio.isPlaying) {
       else if (audio.isPlaying) audio.Stop();
       if (!hasJustLanded) {
         hasJustLanded = true;
         AudioSource.PlayClipAtPoint(landSound, transform.position);
	else {
		if (audio.isPlaying) audio.Stop();
		hasJustLanded = false;

I appreciate any Help.
Thanks in advance.

1- Create an array of clips, assign its clips from the inspector.

var clips : AudioClip[];

2- Add those to what you currently have, and stick PlayRandomClip where you want to play the sounds.

var randPercentage : float = 5; // by default, 50% chance of playing, change this to suit your needs, 0 means 0%, 1 means 10%, 8 means 80%, etc.

function PlayRandomClip()
    var randClip = clips[Random.Range(0, clips.Length)]; // choose a clip at random
    if (GetRandChanceOfPlaying())
        AudioSource.PlayClipAtPoint(randClip, transform.position); // assuming that that's where you like to play the sound from

// This will return true 'randPercentage' % of the time
function GetRandChanceOfPlaying()
    // just making sure randPercentage stays in [0, 10]
    randPercentage = Mathf.Clamp(randPercentage, 0, 10);
    return (Random.Range(0, 10) < randPercentage);

How to store more that one variable

How to get random values