美文网首页
Random7 Using Random5

Random7 Using Random5

作者: GakkiLove | 来源:发表于2018-05-24 22:04 被阅读0次

Given a random generator random5(), the return value of random5() is 0 - 4 with equal probability. Use random5() to implement random7().

class Solution(object):
    def random7(self):
      num = self.random25()
      while num > 20:
        num = self.random25()
      return num % 7
    
    def random25(self):
      return 5 * random5() + random5()

相关文章

网友评论

      本文标题:Random7 Using Random5

      本文链接:https://www.haomeiwen.com/subject/jbsejftx.html