Skip to content

Instantly share code, notes, and snippets.

@PiiXiieeS
Forked from LeverOne/LICENSE.txt
Created February 14, 2017 23:47
Show Gist options
  • Select an option

  • Save PiiXiieeS/c4dc9bcaab7cad97585b5feb3b4e5a10 to your computer and use it in GitHub Desktop.

Select an option

Save PiiXiieeS/c4dc9bcaab7cad97585b5feb3b4e5a10 to your computer and use it in GitHub Desktop.
generate random v4 UUIDs (107 bytes)

UUID

Returns a random v4 UUID of the form 00000000-0000-4000-8000-000000000000.

function c(
a, // placeholder
b // 8 or undefined
){
return a // if the placeholder was passed, return
? ( // a random number from 0 to 15
b | // unless b is 8,
Math.random() // in which case
* 16 // a random number from
>> b/4 // 8 to 11
).toString(16) // in hexadecimal
: ( // or otherwise a concatenated string:
[1e7] + // 10000000 +
-1e3 + // -1000 +
-4e3 + // -4000 +
-8e3 + // -80000000 +
-1e11 // -100000000000,
).replace( // replacing
/1|0|(8)/g, // eights, ones, and zeroes with
b // random hex digits
)
}
function c(a,b){return a?(b|Math.random()*16>>b/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/1|0|(8)/g,c)}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "UUID",
"description": "Generates random UUIDs",
"keywords": [
"UUID",
"ID",
"random"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment