For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
For the best experience, increase the window size or view on a laptop or desktop device
Title | ||
|---|---|---|
Loading... | ||
Given the API rand2() that generates a uniform random integer in the range [1, 2], write a function rand7() that generates a uniform random integer in the range [1, 7]. You can only call the API rand7(), and you shouldn't call any other API. Please do not use a language's built-in random API.
Each test case will have one internal argument n, the number of times that your implemented function rand7() will be called while testing. Note that this is not an argument passed to rand7().
Example 1:
Input: n = 1
Output: [2]
Example 2:
Input: n = 2
Output: [2,8]
Example 3:
Input: n = 3
Output: [3,8,10]
Constraints:
Followup:
rand2() function?rand2()?randN()?Given the API rand2() that generates a uniform random integer in the range [1, 2], write a function rand7() that generates a uniform random integer in the range [1, 7]. You can only call the API rand7(), and you shouldn't call any other API. Please do not use a language's built-in random API.
Each test case will have one internal argument n, the number of times that your implemented function rand7() will be called while testing. Note that this is not an argument passed to rand7().
Example 1:
Input: n = 1
Output: [2]
Example 2:
Input: n = 2
Output: [2,8]
Example 3:
Input: n = 3
Output: [3,8,10]
Constraints:
Followup:
rand2() function?rand2()?randN()?Output