Created
April 3, 2009 18:36
-
-
Save knzai/89887 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
def assign_by_weight(weights) | |
sum = weights.keys.inject(0) { |s,v| s += v } | |
#normalize random over sum | |
#parse weights into some form of mutually exclusive set | |
return result | |
end | |
foo = assign_by_weight(0.5 => :foo, 0.6 => :bar) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment