title: How to generate unique id in javascript?
body: <p>I want to log traffic on website. On every hit I want to generate unique Id that will will be stored in database.
  To generate unique Id I wrote below code, but some time I get same entry in database.</p>
  
  <pre><code> timingVar = 'load_'+Date.now()+'_'+uniqueid();
  
  //function used to generate unique number//
  function uniqueid() {
      var ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      var ID_LENGTH = 8;
      var rtn = '';
      for (var i = 0; i &lt; ID_LENGTH; i++) {
        rtn += ALPHABET.charAt(Math.floor(Math.random() * ALPHABET.length));
      }
      return rtn;
  }
  </code></pre>