Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There have been a couple attempts at this. The question is: do you want actual GUIDs, or just random numbers that <em>look</em> like GUIDs? It's easy enough to generate random numbers.</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>However, note that such values <strong>are not genuine GUIDs</strong>.</p> <p><strong>Note</strong>: the provided code snippet does not follow RFC4122 which requires that the version (<code>4</code>) has to be integrated into the generated output string. <strong>Do not use this answer</strong> if you need compliant GUIDs.</p> <p>Use:</p> <pre><code>var uuid = guid(); </code></pre> <h1>Demo:</h1> <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false"> <div class="snippet-code snippet-currently-hidden"> <pre class="snippet-code-js lang-js prettyprint-override"><code>function guid() { return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } document.getElementById('jsGenId').addEventListener('click', function() { document.getElementById('jsIdResult').value = guid(); })</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>input { font-family: monospace; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;button id="jsGenId" type="button"&gt;Generate GUID&lt;/button&gt; &lt;br&gt; &lt;input id="jsIdResult" type="text" placeholder="Results will be placed here..." readonly size="40"/&gt;</code></pre> </div> </div> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload