funzione
codice:
function random(min,max) {

    return (Math.round((max-min) * Math.random() + min));
}
restituisce un numero tra il range in argomento
quindi tu gli passi 0 e array.length e ti restituisce un indice random