| Class | BareTest::UID |
| In: |
lib/baretest/uid.rb
|
| Parent: | Object |
Generate a unique ID. Not using uuid simply to avoid two dependencies (uuid, and uuid‘s dependency ‘macaddr’).
| Epoch | = | Time.utc(2000,1,1).to_i # :nodoc: |
| value | [R] | The numeric value of the uid (an Integer) |
Create a 128bit (16 Byte) long random number
# File lib/baretest/uid.rb, line 28
28: def initialize
29: now = Time.now
30:
31: # Works for the next 100 years - should be enough
32: # after that, it'll wrap around.
33: time_part_52 = (((now.to_i-Epoch) & 0xffffffff) << 20) + now.usec
34:
35: # Not solid, but for the purposes, should work
36: process_part32 = (Thread.current.object_id ^ Process.pid) & 0xfffffffff
37:
38: # Add a bit of random noise
39: random_part44 = Kernel.rand(0x100000000000)
40:
41: @value = (random_part44 << 84) + (process_part32 << 52) + time_part_52
42: end