Method: FFaker::UUID#uuidv8
- Defined in:
- lib/ffaker/uuid.rb
#uuidv8 ⇒ Object
> UUID version 8 provides an RFC-compatible format for experimental or > vendor-specific use cases. The only requirement is that the variant and > version bits MUST be set as defined in Section 4.1 and Section 4.2. > UUIDv8’s uniqueness will be implementation-specific and MUST NOT be > assumed. > > […] To be clear: UUIDv8 is not a replacement for UUIDv4 Section 5.4 > where all 122 extra bits are filled with random data.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/ffaker/uuid.rb', line 140 def uuidv8 uuid = 0 # custom_a # > The first 48 bits of the layout that can be filled as an # > implementation sees fit. Occupies bits 0 through 47 (octets 0-5). uuid |= rand((2**48) - 1) << 80 # ver # > The 4 bit version field as defined by Section 4.2, set to 0b1000 (8). # > Occupies bits 48 through 51 of octet 6. uuid |= 0b1000 << 76 # custom_b # > 12 more bits of the layout that can be filled as an implementation # > sees fit. Occupies bits 52 through 63 (octets 6-7). uuid |= rand((2**12) - 1) << 64 # var # > The 2 bit variant field as defined by Section 4.1, set to 0b10. # > Occupies bits 64 and 65 of octet 8. uuid |= 0b10 << 62 # custom_c # > The final 62 bits of the layout immediately following the var field # > to be filled as an implementation sees fit. Occupies bits 66 through # > 127 (octets 8-15). uuid |= rand((2**62) - 1) as_string(uuid) end |