Skip to content

Instantly share code, notes, and snippets.

@sandropaganotti-zz
Created June 6, 2011 21:44
Show Gist options
  • Save sandropaganotti-zz/1011189 to your computer and use it in GitHub Desktop.
Save sandropaganotti-zz/1011189 to your computer and use it in GitHub Desktop.
# O(n) Tombolizer
class Extractor
def initialize(range)
@range, @list = range, {}
end
def extract
time = Time.now.to_i
Array.new(@range).each_with_index.map {|e,i|
token = @list[rnd = (time % (@range - i)) + 1] || rnd
@list[rnd] = @list[@range - i] || @range - i
token
}
end
end
p Extractor.new(90).extract
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment