Created
April 9, 2016 19:50
-
-
Save brannondorsey/a16713f1807aa6e395581853258c7a79 to your computer and use it in GitHub Desktop.
Javascript Generate random base60 ID
This file contains hidden or 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
| 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