fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println(
  13. Ideone.generateRandomPassword()
  14. );
  15. }
  16.  
  17. public static String generateRandomPassword ( )
  18. {
  19. int seed = 79;
  20.  
  21. Random rand = new Random( seed );
  22.  
  23. char lowerCase1 = ( char ) ( rand.nextInt( 26 ) + 97 );
  24. char lowerCase2 = ( char ) ( rand.nextInt( 26 ) + 97 );
  25. char upperCase1 = ( char ) ( rand.nextInt( 26 ) + 65 );
  26. char upperCase2 = ( char ) ( rand.nextInt( 26 ) + 65 );
  27. int num1 = rand.nextInt( 10 );
  28. int num2 = rand.nextInt( 10 );
  29. char rand1 = ( char ) ( rand.nextInt( 33 ) + 126 );
  30. char rand2 = ( char ) ( rand.nextInt( 33 ) + 126 );
  31.  
  32. System.out.println( "rand1 int = " + ( int ) rand1 );
  33. System.out.println( "rand2 int = " + ( int ) rand2 );
  34.  
  35. String tempPass = ( "" + lowerCase1 + lowerCase2 + upperCase1 + upperCase2 + num1 + num2 + rand1 + rand2 );
  36. System.out.println( "length of tempPass: " + tempPass.length() );
  37.  
  38. return tempPass;
  39. }
  40. }
Success #stdin #stdout 0.17s 52924KB
stdin
Standard input is empty
stdout
rand1 int = 155
rand2 int = 138
length of tempPass: 8
koLN59›Š