Created
May 4, 2017 16:26
-
-
Save davidmerfield/41581bc6aa8cf25abef9b6ed38326a16 to your computer and use it in GitHub Desktop.
Pretty IDs
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 lower = 'acemnorsuvwxz'.split(''); | |
var upper = '1234567890ABCDEFGHJKMNPRSTUVWXYZ'.split(''); | |
var chars = lower; | |
var LEN = 12; | |
var PREFIX = 'site'; // site file post theme | |
function uid () { | |
var res = ''; | |
while (res.length < LEN) | |
res += chars[Math.floor(Math.random()*chars.length)]; | |
return PREFIX + '-' + res; | |
} | |
function simulate () { | |
var collisions = {}; | |
var id; | |
var total = 1000; | |
for (i=0;i<total;i++) { | |
id = uid(); | |
console.log(id+'.blot.im'); | |
if (collisions[id] !== undefined) { | |
console.log('COLLISION', id, 'defined on iteration', collisions[id], 'currently on:', i); | |
} | |
collisions[id] = i; | |
} | |
console.log('SIMULATION COMPLETE for', total, 'runs.'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment