![]() |
VOOZH | about |
Write a program to generate a random two-digit number.
Example 1: 73
Example 2: 26
Approach: To solve the problem, follow the below idea:
We can generate a random two-digit number by generating a random integer first and then modulo it by 90. Now, after modulo 90 the remainder can be in the range 0 to 89, so in order to have the remainder as a two-digit number, we can further add 10 to make the range 10 to 99.
Step-by-step algorithm:
Below is the implementation of the algorithm:
Generated Random Number: 47
Time Complexity: O(1), it takes constant time to generate a random number.
Auxiliary Space: O(1)