Leetcode 903 Solution
This article provides solution to leetcode question 903 (implement-rand10-using-rand7)
Access this page by simply typing in "lcs 903" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/implement-rand10-using-rand7
Solution
# The rand7() API is already defined for you.
# def rand7():
# @return a random integer in the range 1 to 7
class Solution:
def rand10(self):
"""
:rtype: int
"""
while True:
row = rand7() - 1
col = rand7() - 1
val = col + row * 7
if val < 40:
return 1 + (val % 10)