Last active
September 22, 2018 05:02
-
-
Save woodRock/892c1e840a3dc333fa8e5116d1d59371 to your computer and use it in GitHub Desktop.
Using a function rand5() that returns an integer from 1 to 5 (inclusive) with uniform probability, implement a function rand7() that returns an integer from 1 to 7 (inclusive).
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
#!/usr/bin/env ruby | |
def rand5() | |
rand(5) + 1 | |
end | |
def rand7() | |
(7 * rand5()) / 5 | |
end | |
puts rand7() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment