Con este script obtendremos un valor aleatorio que este contenido dentro de un array que le pasemos.
Los valores estan contenidos en el array llamado myArray.
// Randomize elements in an array without duplicates
// By Jesse Stratford,
Para ver los enlaces debes ser usuario
Crear Usuario o
Hacer Sesion // Usage example:
// myArray = [0,1,2,3,4,5]
// trace (randomizeArray("myArray"))
function remItem (source, index) {
var before = _root[source].slice(0, index);
var after = _root[source].slice(index+1, _root[source].length);
_root[source] = before.concat(after);
}
function randomizeArray (source) {
var tmpArray = [];
var arrayLength = _root[source].length;
for (var i = 0; i<arrayLength; i++) {
var index = Math.floor(Math.random()*_root[source].length);
tmpArray
= _root[source][index];
remItem(source, index);
}
return tmpArray;
}