Array.prototype.randomize

Clasificado bajo: AS2 (deprecated), Prototipos, Array — drus @ 1:06 am

Un simple prototipo para desordenar una array aleatoriamente.

Actionscript:
Array.prototype.randomize = function() {
    var l = this.length;
    for (var i = 0; i <l; i++) {
        var alea = Math.ceil(Math.random() * l);
        var tmp = this[i];
        this[i] = this[alea];
        this[alea] = tmp;
    }
};
//Uso:
mi_array=[1,2,3,4,5,6,7];
mi_array.randomize();
trace(mi_array);

Enlaces relacionados: No related posts, | Tags: , ,



AS_toolKit | Powered by WordPress | Skinned by Drus Unlimited | RSS Feed | Copyleft