getButterfly Logo getButterfly

This small functions generates a unique string:

function generateUniqueString() {
    var ts = String(new Date().getTime()), i = 0, out = '';

    for(i=0;i<ts.length;i+=2) {
        out += Number(ts.substr(i, 2)).toString(36);

    return ('prefix' + out);

JSFiddle Demo

Note: In some very rare instances, 1 in 100.000.000 cases with high-traffic web apps, the string might be identical.

Subscribe to getButterfly Blog

Once a week or so we send an email with our best content. We never bug you, we just send you our latest piece of content.

If you found any value in this post, agree, disagree, or have anything to add - please do. I use comments as my #1 signal for what to write about. Read our comment policy before commenting! Comments such as "Thank you!", "Awesome!", "You're the man!" are either marked as spam or stripped from URL.

Leave a Reply

Your email address will not be published. Required fields are marked *