Skip to content

Instantly share code, notes, and snippets.

@adelevie
Created May 26, 2010 18:41
Show Gist options
  • Select an option

  • Save adelevie/414870 to your computer and use it in GitHub Desktop.

Select an option

Save adelevie/414870 to your computer and use it in GitHub Desktop.
#read more about abingo here: http://www.bingocardcreator.com/abingo/
def self.find_alternative_for_user(test_name, alternatives)
alternatives_array = retrieve_alternatives(test_name, alternatives)
alternatives_array[self.modulo_choice(test_name, alternatives_array.size)]
end
#Quickly determines what alternative to show a given user. Given a test name
#and their identity, we hash them together (which, for MD5, provably introduces
#enough entropy that we don't care) otherwise
def self.modulo_choice(test_name, choices_count)
Digest::MD5.hexdigest(Abingo.salt.to_s + test_name + self.identity.to_s).to_i(16) % choices_count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment