Skip to content

Instantly share code, notes, and snippets.

@FrancoB411
Last active October 7, 2015 00:58
Show Gist options
  • Select an option

  • Save FrancoB411/3080400 to your computer and use it in GitHub Desktop.

Select an option

Save FrancoB411/3080400 to your computer and use it in GitHub Desktop.
Method returns a random result based on the probability threshold passed in.
# returns true N percent of the time.
# pass in a threshold number N from 1-100
def random_threshold (percentage)
# number_pool of 100 numbers.
number_pool = (1..100).to_a
# return true if random number_pool sample is below threshold N.
number_pool.sample < percentage ? true : false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment