Created
June 16, 2013 22:55
-
-
Save jish/5793764 to your computer and use it in GitHub Desktop.
percent
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
| # Q: How do I make something happen 25% of the time | |
| # A: rand(4) == 0 | |
| # How? | |
| results = Hash.new(0) | |
| 10_000.times do | |
| results[rand(4)] += 1 | |
| end | |
| puts results.inspect # => {3=>2482, 1=>2507, 2=>2506, 0=>2505} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment