Generate Random One Time Password(OTP) using Java
import java.util.Random; public class OtpGenerator { public static String generateRandomOtp(int length) { // Define the characters that can be used in the OTP String validChars = "0123456789"; // You can add more characters if needed // Initialize a random number generator Random random = new Random(); // Create a StringBuilder to build the OTP StringBuilder otpBuilder = new StringBuilder(length); // Generate random characters for the OTP for (int i = 0; i <