Show HN: Givemeguid.com – CLI/curl friendly GUIDs
givemeguid.com
givemeguid.com
If you're writing some kind of application, pretty much every language/framework can generate UUIDs, and even if yours doesn't, just generate a 128-bit number, stamp the v4 UUID bits into it, reformat it, and you're done. Calling out to a 3rd-party service is insane for that use case anyway.
uuidgen is provided by the Windows SDK - exactly the same usage than in *nix
There's no shortage of ways to generate GUIDs, that's for sure!
I was surprised to see that there is no "built-in" mechanism in JS to generate a GUID. As a C# dev, I'm used to Guid.NewGuid()
https://gist.github.com/jed/982883
If you google "generate uuid javascript" you can find approaches from Math.random to node/browser `crypto` module to shelling out OS random.
One of the main benefits of guid generation is that you don't need to synchronize with anything to generate a unique ID, so it's weird to incur an http request, especially to someone else's service. At that point you might as well just phone home to your own service.
window.crypto.getRandomValues() should be used instead.
The quality and seeding of Math.random() is implementation-dependent and not generally good enough everywhere to prevent collisions. Many seed with the just the system time.
Source: I have personally seen such collisions in a production web app with 700k users. A Web search for “Javacsript GUID collision” shows that many others have as well. We switched to the cryptographic generator and the collisions disappeared.
Most people format 128-bit random numbers into a UUID just so it's obvious at a glance what it is: a guid. Even if it's not technically a UUIDv4 because it doesn't have the magic bits.
That seems hyperbolic to me. If you rely on UUID for security, it seems, to me, something is wrong in your architecture and the security flaw lies there.
When would you, legitimate, rely on GUID/UUID for security?
Math.random().toString(32).slice(2,10)
Gives you an 8 character GUID.... but maybe don't use it for anything important....cat /proc/sys/kernel/random/uuid
cat: /proc/sys/kernel/random/uuid: No such file or directory
GUID() { format = %A_FormatInteger% ; save original integer format SetFormat Integer, Hex ; for converting bytes to hex VarSetCapacity(A,16) DllCall("rpcrt4\UuidCreate","Str",A) Address := &A Loop 16 { x := 256 + *Address ; get byte in hex, set 17th bit StringTrimLeft x, x, 3 ; remove 0x1 h = %x%%h% ; in memory: LS byte first Address++ } SetFormat Integer, %format% ; restore original format h := SubStr(h,1,8) . "-" . SubStr(h,9,4) . "-" . SubStr(h,13,4) . "-" . SubStr(h,17,4) . "-" . SubStr(h,21,12) return h }
There's also https://www.newguid.org/
Which is a perfect example why it is bad to rely on a service like this to generate your IDs.
What if I bought it and started emitting predictable IDs? Or non-unique IDs?
I use the following alias to generate uuids
function uuid() { uuidgen | tr "[:upper:]" "[:lower:]" | tr -d "\n\r" }
I then pair it with pbcopy on the mac uuidgen | pbcopy uuidgen | awk '{ printf "\"" $1 "\"" }' | xclip -selection clipboarduuidgen is one. My personal favorite is this snippet.
$ id=$(openssl rand 1000 | openssl sha1) && printf "%s${id:0:8}\n"
alias uuid='python -c "import uuid;print(str(uuid.uuid4()))"'Is shorter and easier.