#470
Implement Rand10() Using Rand7()
specialist · 955 · lc medium +32 · verified · 46.3% accepted · 1,171 likes · top 30%
Description
You are given access to rand7(), which uniformly returns a random integer in [1, 7]. Implement rand10() so that it uniformly returns a random integer in [1, 10]. You may only call rand7(); no other random API is permitted.
Each test case has an internal count n indicating how many times your rand10() will be called.
Example 1:
Input: n = 1
Output: [2]
Example 2:
Input: n = 2
Output: [2,8]
Example 3:
Input: n = 3
Output: [3,8,10]
Code
1
2
3
4
5
6
7
8
9
10