Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

import java.util.

Random;

public class randompass{


public static void main(String[] args) {
System.out.println(generatePassword(8));
}

private static char[] generatePassword(int length) {


String name = "PraveenKumar";
String age = "22";
String id = "1234567890";

String combinedChars = name + age + id ;


Random random = new Random();
char[] password = new char[length];

password[0] = age.charAt(random.nextInt(age.length()));
password[1] = name.charAt(random.nextInt(name.length()));

password[2] = id.charAt(random.nextInt(id.length()));

for(int i = 4; i< length ; i++) {


password[i] =
combinedChars.charAt(random.nextInt(combinedChars.length()));
}
return password;
}
}

Output:
2v3_r50r

You might also like