title: Generate unique random string with Javascript
body: <p>I am creating an app where I sometimes need to allow user to generate some random strings. I would like to force that to be generated in the following format:</p>
  
  <pre><code>xxxx-xxxx-xxxx
  </code></pre>
  
  <p>Where "x" is some number [0-9] or character [A-Z]. What would the most efficient way to do this? When generated, I would also need to check does it already exist in database so I am a little bit worried about the time which it would take.</p>