Skip to content

Instantly share code, notes, and snippets.

@dosjota
Created December 2, 2014 20:11
Show Gist options
  • Save dosjota/1cd9f582881d72879ffb to your computer and use it in GitHub Desktop.
Save dosjota/1cd9f582881d72879ffb to your computer and use it in GitHub Desktop.
Generar id único ejemplo: _idUnico(5,'_')
var _idUnico = function(secuencia, separador) {
//valores por defecto
secuencia = typeof(secuencia) != 'undefined' ? secuencia : 1;
separador = typeof(separador) != 'undefined' ? separador : '-';
var id = '',
a=1;
for (var i = 0; i < secuencia; i++) {
separador = ( secuencia=== a) ? '': separador;
id = id+Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)+separador;
a++;
}
return id
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment