Skip to content

Instantly share code, notes, and snippets.

@woodRock
Last active September 22, 2018 05:02
Show Gist options
  • Save woodRock/892c1e840a3dc333fa8e5116d1d59371 to your computer and use it in GitHub Desktop.
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).
#!/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