Created
March 29, 2019 11:49
-
-
Save FoC-/738b3258e50bff6969729ba8f75fc6dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # https://github.com/mongodb/bson-ruby/blob/master/lib/bson/object_id.rb#L369 | |
| # https://repl.it/languages/ruby | |
| require "digest/md5" | |
| require "socket" | |
| @counter = rand(0x1000000) | |
| puts "counter: #{@counter}" | |
| @machine_id = Digest::MD5.digest(Socket.gethostname).unpack("N")[0] | |
| puts "machine_id: #{@machine_id}" | |
| @process_id = Process.pid % 0xFFFF | |
| puts "process_id: #{@process_id}" | |
| @id = [::Time.new.to_i, @machine_id, @process_id, @counter << 8 ].pack("N NX lXX NX") | |
| puts "id: #{@id.unpack("H*").first}"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment