Last active
October 7, 2015 00:58
-
-
Save FrancoB411/3080400 to your computer and use it in GitHub Desktop.
Method returns a random result based on the probability threshold passed in.
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
| # 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