Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Lines changed: 21 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /