Method: FFaker::UUID#uuidv6
- Defined in:
- lib/ffaker/uuid.rb
#uuidv6 ⇒ Object
> UUID version 6 is a field-compatible version of UUIDv1 Section 5.1, > reordered for improved DB locality. It is expected that UUIDv6 will > primarily be used in contexts where UUIDv1 is used. Systems that do not > involve legacy UUIDv1 SHOULD use UUIDv7 instead.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ffaker/uuid.rb', line 51 def uuidv6 = rand((2**60) - 1) uuid = 0 # time_high # > The most significant 32 bits of the 60 bit starting timestamp. # > Occupies bits 0 through 31 (octets 0-3). # @note Shifts 28 bits to remove `time_mid` and `time_low`. uuid |= ( >> 28) << 96 # time_mid # > The middle 16 bits of the 60 bit starting timestamp. Occupies bits 32 # > through 47 (octets 4-5). # @note Shifts 12 bits to remove `time_low`. uuid |= (( >> 12) & ((2**16) - 1)) << 80 # ver # > The 4 bit version field as defined by Section 4.2, set to 0b0110 (6). # > Occupies bits 48 through 51 of octet 6. uuid |= 0b0110 << 76 # time_low # > 12 bits that will contain the least significant 12 bits from the 60 # > bit starting timestamp. Occupies bits 52 through 63 (octets 6-7). uuid |= ( & ((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 # clk_seq # > The 14 bits containing the clock sequence. Occupies bits 66 through # > 79 (octets 8-9). # # (earlier in the document) # > The clock sequence and node bits SHOULD be reset to a pseudo-random # > value for each new UUIDv6 generated; however, implementations MAY # > choose to retain the old clock sequence and MAC address behavior from # > Section 5.1. uuid |= rand((2**14) - 1) << 48 # node # > 48 bit spatially unique identifier. Occupies bits 80 through 127 # > (octets 10-15). uuid |= rand((2**48) - 1) as_string(uuid) end |