Skip to content

Instantly share code, notes, and snippets.

@s-mage
Last active December 19, 2015 19:49
Show Gist options
  • Save s-mage/6009365 to your computer and use it in GitHub Desktop.
Save s-mage/6009365 to your computer and use it in GitHub Desktop.
Simple implementation of probability distribution.
weights = Array.new(2288) { |x| 1 / 2288.0 }
t = 0.0
weights.map! { |x| t += x; t }
random_value = Random.new.rand
weights.find_index { |x| random_value - x <= 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment