# LeetCode - 0470. Implement Rand10() Using Rand7()
### 題目網址:https://leetcode.com/problems/implement-rand10-using-rand7/
###### tags: `LeetCode` `Medium` `模擬` `數學`
```cpp=
/*
-LeetCode format-
Problem: 470. Implement Rand10() Using Rand7()
Difficulty: Medium
by Inversionpeter
*/
// The rand7() API is already defined for you.
// int rand7();
// @return a random integer in the range 1 to 7
class Solution {
public:
int rand10() {
static int result;
do {
result = rand7() + rand7() * 7;
} while (result > 47);
return result % 10 + 1;
}
};
```