Hay una alternativa menos costosa que es
1)almacenás los valores posibles en un array
2) Mezclas el array por ejemplo con la función
Código Javascript
:
Ver originalArray.prototype.mezclar= function() {
for ( var i = this.length-1; i > 0; i-- ) {
var j = Math.floor( i * Math.random() );
var tmp = this[ j ];
this[ j ] = this[ i ];
this[ i ] = tmp;
}
return this;
}
3)Recorres el array de 0 hasta su length -1 con un simple for.