Skip to content

@sentientmonkey /friendly_guid.rb
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
class FriendlyGuid
attr_reader :mask
def initialize(mask)
@mask = mask
end
def guid(id)
(id.to_i ^ mask).to_s(36)
end
def id(guid)
guid.to_i(36) ^ mask
end
end
if __FILE__ == $0
mask = Random.new.rand(2**64)
id = Random.new.rand(2**64)
f = FriendlyGuid.new(mask)
puts "mask = #{mask}"
puts "id = #{id}"
g = f.guid(id)
puts "guid = #{g}"
puts "id = #{f.id(g)}"
end
mask = 1000723141368662252
id = 2465229093246480629
guid = q6parhf03kt5
id = 2465229093246480629
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.