Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
, where each x
is replaced with a random hexadecimal digit from 0 to f, and y
is replaced with a random hexadecimal digit from 8 to b.
There's also @LeverOne's approach using iteration, which is one byte shorter.
@jsejcksn you probably should hoist your
hex
table to the parent scope, to avoid recalculating every time. Also note (though you might not care, depending on your use-case) that I was deliberately avoiding loops in my version for performance reasons - usingmap
makes for fewer lines, but much slower execution. 🙂