4 ms·
The RFC outlines a single variant of UUID, and describes five different versions of this variant. One of these versions is random. The author, however, is not u
by mikebabineau 14y ago
The RFC outlines a single variant of UUID, and describes five different versions of this variant. One of these versions is random. The author, however, is not using this version. I may be mistaken fact, but the uuid Ruby gem he used appears to implement a different variant altogether. From wikipedia:
In the canonical representation, xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx, the
most significant bits of N indicates the variant (depending on the variant;
one, two or three bits are used). The variant covered by the UUID
specification is indicated by the two most significant bits of N being 1 0
(i.e. the hexadecimal N will always be 8, 9, A, or B).
In the variant covered by the UUID specification, there are five versions.
For this variant, the four bits of M indicates the UUID version (i.e. the
hexadecimal M will either be 1, 2, 3, 4, or 5).
The examples from the blog post don't appear to fit the RFC variant:
855ff330-5ce6-0130-d84d-12313d05011b
33aa4b00-5ce7-0130-d84d-12313d05011b
If the gem used [variant 1] version 4 UUIDs instead, this wouldn't be a problem (http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 http://en.wikipedia.org/wiki/Universally_unique_identifier#V...):
Version 4 UUIDs use a scheme relying only on random numbers. This algorithm
sets the version number as well as two reserved bits. All other bits are set
using a random or pseudorandom data source. Version 4 UUIDs have the form
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y
is one of 8, 9, a, or b. e.g. f47ac10b-58cc-4372-a567-0e02b2c3d479.
Ruby 1.9 includes version 4 UUIDs as a built-in: SecureRandom.uuid. The author should consider using that instead.
- bradleybuda 14y agoWe ended up using Ruby's SecureRandom.hex, which is 128 bits of the form "e7e12f9b82f71d90b678373c360e497c" - roughly equivalent to the 126 bits of randomness you get from a version 4 UUID.