470. Implement Rand10() Using Rand7() (Medium) - TengnanYao/daily_leetcode GitHub Wiki

# 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
        """
        m = (rand7() - 1) * 7 + rand7()
        while m > 40:
            m = (rand7() - 1) * 7 + rand7()
        return m % 10 + 1