Skip to content

Instantly share code, notes, and snippets.

@brannondorsey
Created April 9, 2016 19:50
Show Gist options
  • Select an option

  • Save brannondorsey/a16713f1807aa6e395581853258c7a79 to your computer and use it in GitHub Desktop.

Select an option

Save brannondorsey/a16713f1807aa6e395581853258c7a79 to your computer and use it in GitHub Desktop.
Javascript Generate random base60 ID
function genId(len) {
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ23456789'.split('');
var id = '';
for (var i = 0; i < len; i++) {
var index = Math.floor(Math.random() * chars.length);
id += chars[index];
}
return id;
// use this if you want an ID based on the month, day, hour, minute, and second
// var now = new Date();
// id += chars[now.getMonth()];
// id += chars[now.getDate()];
// id += chars[now.getHours()];
// id += chars[now.getMinutes()];
// id += chars[now.getSeconds()];
// return id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment