Skip to content

Commit 40ad26a

Browse files
Add files via upload
1 parent 791b90c commit 40ad26a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// The rand7() API is already defined for you.
2+
// int rand7();
3+
// @return a random integer in the range 1 to 7
4+
5+
class Solution
6+
{
7+
public:
8+
int rand10()
9+
{
10+
while (true)
11+
{
12+
int bit1 = rand7();
13+
int bit2 = rand7();
14+
15+
int res = (bit1 - 1) * 7 + bit2;
16+
17+
if (1 <= res && res <= 40)
18+
return res % 10 + 1;
19+
}
20+
}
21+
};

0 commit comments

Comments
 (0)