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.
A UUID generator is frequently treated as a black box by those who use one anyway. For such people, they'd rather have a black box with less code rather than a black box with more code, even if the code was the product of a nerdy online challenge. 🤷♂️