Created
December 22, 2011 17:36
-
-
Save potatosalad/1511135 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/md5' | |
def bson_id | |
[ | |
'%08x' % Time.now.utc.to_i, # 4 bytes | |
Digest::MD5.hexdigest(`hostname`.strip)[0..5], # 3 bytes | |
'%04x' % $$, # 2 bytes | |
'%06x' % rand(0..('f' * 6).to_i(16)) # 3 bytes | |
] # 12 bytes total | |
end | |
puts bson_id.inspect | |
puts bson_id.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment