title: Create Globally Unique ID in JavaScript
body: <p>I have a script that, when a user loads, creates a unique id. Which is then saved in <code>localStorage</code> and used for tracking transactions. Sort of like using a cookie, except since the browser is generating the unique id there might be collisions when sent to the server. Right now I'm using the following code:</p>
  
  <pre class="lang-js prettyprint-override"><code>function genID() {
      return Math.random().toString(36).substr(2)
          + Math.random().toString(36).substr(2)
          + Math.random().toString(36).substr(2)
          + Math.random().toString(36).substr(2);
  }
  </code></pre>
  
  <p>I realize this is a super basic implementation, and want some feedback on better ways to create a "more random" id that will prevent collisions on the server. Any ideas?</p>