Ver Mensaje Individual
  #4 (permalink)  
Antiguo 22/05/2010, 13:46
Avatar de zerokilled
zerokilled
Javascripter
 
Fecha de Ingreso: abril-2009
Ubicación: Isla del Encanto, La Borinqueña [+>==]
Mensajes: 8.050
Antigüedad: 15 años
Puntos: 1485
Respuesta: Numero aleatorio que no se repita

te voy a mostrar las funciones por la unica razon que ya tengo una pequeña libreria que contiene las funciones para lo que requieres.
Código:
// extract values into variables set as global;
// use: walk;
Array.prototype.list= function(){
this.walk(function(value, i, args){
if(i < args.length) self[args[i]] = value;
}, arguments);
}

// traverse each element of array and apply a function;
Array.prototype.walk= function(callback, args){
	try{
	for(var i = 0; i < this.length; i++) callback.call(this, this[i], i, args);
	return true;
	} catch(e){
	return false;
	}
}

// shuffle the order of elements;
// Stephen Chapman (alias felgall in webdeveloper.com)
Array.prototype.shuffle= function(){
this.sort(function(){return Math.round(Math.random()) - .5;});
return this;
}
las tres funciones son parte del prototipo del array, pero las que mas te deben interesar son shuffle y list. creas el array, luego invocas el metodo shuffle y luego list. en list, le pasas como argumento una serie de string el cual corresponde a los nombres de variables.
__________________
la maldad es una virtud humana,
y la espiritualidad es la lucha del hombre contra su maldad.