We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 16fa698 commit c5721c1Copy full SHA for c5721c1
1 file changed
implement-rand10-using-rand7.py
@@ -0,0 +1,9 @@
1
+class Solution(SolBase):
2
+ def rand10(self):
3
+ # 推导过程可以参考 https://www.jianshu.com/p/1127e746da12
4
+ while True:
5
+ i = (self.rand7() - 1) * 7 + (self.rand7() - 1)
6
+ if (i >= 1) and (i <= 10): # 因为i在1-10之间均匀分布,超出的值不要!
7
+ return i
8
+
9
+# medium: https://www.lintcode.com/problem/1496
0 commit comments