一、力扣470. 用Rand7()实现Rand10()



参考力扣官方题解:
https://leetcode-cn.com/problems/implement-rand10-using-rand7/solution/yong-rand7-shi-xian-rand10-by-leetcode-s-qbmd/
代码如下:
class Solution
{
public:
int rand10()
{
int row, col, idx;
do
{
row = rand7();
col = rand7();
idx = col + (row - 1) * 7;
} while (idx > 40);
return 1 + (idx - 1) % 10;
}
};