Skip to content

Instantly share code, notes, and snippets.

@alejandro
Created September 3, 2011 22:17
Show Gist options
  • Save alejandro/1191867 to your computer and use it in GitHub Desktop.
Save alejandro/1191867 to your computer and use it in GitHub Desktop.
Generar random ID's
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;
}
@alejandro
Copy link
Author

function load(ing){ 
  var ni = document.getElementById('myDiv');
  var newdiv = document.createElement('p');
  newdiv.setAttribute('id',ing);
  newdiv.innerHTML = '<small> ' + ing + '</small>';
  ni.appendChild(newdiv);
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment