Loading

[Python手撕]用 Rand7() 实现 Rand10()

class Solution:

    def rand10(self):
        x = rand7()
        y = rand7()
        index = (x-1)*7 + y
        while index>40:
            x = rand7()
            y = rand7()
            index = (x-1)*7 + y
        return (index-1) // 4 + 1
posted @ 2024-09-19 11:47  Duancf  阅读(22)  评论(0)    收藏  举报