Program to generate a random two-digit number Last Updated : 18 Jan, 2024 Comments Improve Suggest changes Like Article Like Report Write a program to generate a random two-digit number. Example 1: 73Example 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: Seed the random number generator to ensure different random numbers on each run.Generate a random number within the range of two-digit numbers (10 to 99).Below is the implementation of the algorithm: C++ #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int main() { // Seed the random number generator with the current // time srand(time(0)); // Generate a random two-digit number int randomNumber = rand() % 90 + 10; cout << "Generated Random Number: " << randomNumber << endl; return 0; } C #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { srand(time(0)); // Seed the random number generator with // the current time int randomNumber = rand() % 90 + 10; // Generate a random two-digit number printf("Generated Random Number: %d\n", randomNumber); return 0; } Java import java.util.Random; public class RandomNumberGenerator { public static void main(String[] args) { Random rand = new Random(); int randomNumber = rand.nextInt(90) + 10; // Generate a random two-digit number System.out.println("Generated Random Number: " + randomNumber); } } Python3 import random def main(): # Generate a random two-digit number random_number = random.randint(10, 99) print(f"Generated Random Number: {random_number}") if __name__ == "__main__": main() C# using System; class Program { static void Main() { Random rand = new Random(); int randomNumber = rand.Next( 10, 100); // Generate a random two-digit number Console.WriteLine("Generated Random Number: " + randomNumber); } } JavaScript function generateRandomNumber() { let randomNumber = Math.floor(Math.random() * 90) + 10; // Generate a random two-digit number console.log("Generated Random Number: " + randomNumber); } generateRandomNumber(); OutputGenerated Random Number: 47 Time Complexity: O(1), it takes constant time to generate a random number.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to generate a random two-digit number S srinam Follow Improve Article Tags : DSA Similar Reads Program to generate a random single digit number Write a program to generate a random single-digit number. Example 1: 7Example 2: 3 Approach: To solve the problem, follow the below idea: To generate a random single-digit number, we can first generate a random integer and then take apply modulo to get the last digit of that random integer. This las 2 min read Program to generate a random three digit even number Write a program to generate a random three-digit even number. Examples: Example 1: 482Example 2: 736 Approach: To solve the problem, follow the below idea: We can generate a random three-digit number by generating a random integer first and then modulo it by 900. Now, after modulo with 900, the rema 3 min read Program to generate a random number between L to R Write a program that generates a random number within a specified range [L, R]. The program should take two integers, L and R, as input and output a random number between L and R (inclusive). Examples: Input: L = 10, R = 20Output: 15 Input: L = -5, R = 5Output: 3 Approach: To solve the problem, foll 2 min read Program to generate random string in PHP Given a size N and the task is to generate a random string of size N. Examples: Input: 5Output: eR3DsInput: 10Output: MPRCyBgdcnUsing a Domain String and Random IndexCreate a domain string that contains small letters, capital letters, and the digits (0 to 9). Then generate a random number pick the c 2 min read R Program to Generate a Random Password Password generation is a common task in programming languages. It is required for security applications and various accounts managing systems. A random password is not easily guessable which also improves the security of the accounts systems with the aim to protect information. In R Programming Lang 4 min read How to Generate Random Numbers in R Random number generation is a process of creating a sequence of numbers that don't follow any predictable pattern. They are widely used in simulations, cryptography and statistical modeling. R Programming Language contains various functions to generate random numbers from different distributions lik 2 min read How to generate a random number between 0 and 1 in Python ? The use of randomness is an important part of the configuration and evaluation of modern algorithms. Here, we will see the various approaches for generating random numbers between 0 ans 1. Method 1: Here, we will use uniform() method which returns the random number between the two specified numbers 1 min read Generate a Random Float Number in C++ Random floating numbers can be generated using 2 methods: Using rand()Using uniform real distribution1. Use of rand() We can generate random integers with the help of the rand() and srand() functions. There are some limitations to using srand() and rand(). To know more about the srand() and rand() f 5 min read Generate a Random Number between 0 and 1 The Task is to generate a random number between 0 and 1. It is obvious that the number between 0 and 1 will be a floating point number. To generate a random number between 0 and 1, we will make use of the rand() function. The rand() function creates a random number. Approach: Generating a Random Num 5 min read Like