Skip to content

Instantly share code, notes, and snippets.

@vmsp
Created September 11, 2024 21:39
Show Gist options
  • Save vmsp/266d4635c413ae663e20ced3a8ba7f89 to your computer and use it in GitHub Desktop.
Save vmsp/266d4635c413ae663e20ced3a8ba7f89 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
module Simpleflake
module_function
EPOCH = 946_702_800
def generate
s = ((Time.now.to_f - EPOCH) * 1000).to_i
r = SecureRandom.random_number(0..((2**23) - 1))
(s << 23) + r
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment