title: Javascript GUID (Global Unique Identifier) Generator Explanation
body: <p>I'm trying to write a JavaScript GUID generator for 8 characters including lowercase / uppercase letters, numbers and symbols. I found these solutions but need an explanation on what is happening in each. Originally I thought I'd need a string holding all the letters/numbers/symbols that I would index into with random number function to build a new GUID, but these solutions seem to create numbers/letters/symbols out of thin air.</p>
  
  <p>In solution 1, what is the purpose of "1+" and "0x10000"? What is the purpose of ".toString(16)" and ".substring(1)" and how is it generating numbers/symbols/AND letters with just that little bit of code?</p>
  
  <p>Solution 1:</p>
  
  <pre><code>function guid() {
    function s4() {
      return Math.floor((1 + Math.random()) * 0x10000)
        .toString(16)
        .substring(1);
    }
    return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
      s4() + '-' + s4() + s4() + s4();
  }
  </code></pre>
  
  <p>In solution 2, I see how the GUID is 32 characters long but don't understand why Math.Random is being multiplied by specifically "16", with a toString(16) attached but no ".substring(x)" this time?</p>
  
  <p>Solution 2:</p>
  
  <pre><code>function generateGuid() {
    var result, i, j;
    result = '';
    for(j=0; j&lt;32; j++) {
      if( j == 8 || j == 12|| j == 16|| j == 20) 
        result = result + '-';
      i = Math.floor(Math.random()*16).toString(16).toUpperCase();
      result = result + i;
    }
    return result;
  }
  </code></pre>
  
  <p>No need to explain the structure of a GUID nor what is a hyphen is XD</p>
  
  <p>Any and all detailed explanations are appreciated!</p>