Created
September 3, 2011 22:17
-
-
Save alejandro/1191867 to your computer and use it in GitHub Desktop.
Generar random ID's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var letra = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; | |
var letra_o_numero, | |
numero=0, | |
string=""; | |
function id() { | |
for(i=0;i<=5;i++){ | |
letra_o_numero = Math.floor(Math.random(5)*2); | |
//si es 1, que el string sea una letra | |
if (letra_o_numero == 1){ | |
string += letra[Math.floor(Math.random(5)*26)]; | |
}else{ | |
// si es 2, que escriba un numero | |
numero = Math.floor(Math.random(5)*10); | |
string += numero; | |
} | |
} | |
// el String quedara de largo 15 | |
return string; | |
} |
Author
alejandro
commented
Sep 3, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment