Skip to content

Instantly share code, notes, and snippets.

@manveru
Created July 6, 2010 06:11
Show Gist options
  • Save manveru/465073 to your computer and use it in GitHub Desktop.
Save manveru/465073 to your computer and use it in GitHub Desktop.
words = {
'hello' => 100,
'world' => 50,
'this' => 200,
}
storage = {}
sum = 0
words.each do |word, weight|
top = sum + weight
storage[(sum..top)] = word
sum = top
end
100.times do
r = rand(sum)
p storage.find{|range, word| range.include?(r) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment