Package com. tianren. util;
Import java. util. Random;
/**
* Randomstring. Java
* Utils class
* @ Author jinxx
* @ Version 1.0
**/
Public class randomstring {
/** Returns an uppercase random letter string */
Public static string getrandomstringu (INT length ){
String STR = "abcdefghijklmnopqrstuvwxyz ";
Random random = new random ();
Stringbuffer sb = new stringbuffer ();
For (int I = 0; I <length; ++ I ){
Int number = random. nextInt (26 );
Sb. append (str. charAt (number ));
}
Return sb. toString ();
}
/** Returns a lowercase random letter string */
Public static String getRandomStringL (int length ){
String str = "abcdefghijklmnopqrstuvwxyz ";
Random random = new random ();
Stringbuffer sb = new stringbuffer ();
For (INT I = 0; I <length; ++ I ){
Int number = random. nextint (26 );
SB. append (Str. charat (number ));
}
Return sb. tostring ();
}
/** Returns a random number string [0-9] */
Public static string getrandomstringn10 (INT length ){
String STR = "0123456789 ";
Random random = new random ();
Stringbuffer sb = new stringbuffer ();
For (INT I = 0; I <length; ++ I ){
Int number = random. nextint (10 );
SB. append (Str. charat (number ));
}
Return sb. tostring ();
}
/** Returns a random number string [1-9] */
Public static string getrandomstring) (INT length ){
String STR = "123456789 ";
Random random = new random ();
Stringbuffer sb = new stringbuffer ();
For (INT I = 0; I <length; ++ I ){
Int number = random. nextint (9 );
SB. append (Str. charat (number ));
}
Return sb. toString ();
}
/** Return a random number [1-9] */
Public static int getRandomIntN9 (int length ){
String str = "123456789 ";
Random random = new Random ();
StringBuffer sb = new StringBuffer ();
For (int I = 0; I <length; ++ I ){
Int number = random. nextInt (9 );
SB. append (Str. charat (number ));
}
Return integer. parseint (sb. tostring ());
}
/** Return a random number [0-9] */
Public static int getrandomintn10 (INT length ){
String STR = "0123456789 ";
Random random = new random ();
Stringbuffer sb = new stringbuffer ();
For (int I = 0; I <length; ++ I ){
Int number = random. nextInt (10 );
Sb. append (str. charAt (number ));
}
Return Integer. parseInt (sb. toString ());
}
/** Returns a string consisting of uppercase and lowercase letters and digits */
Public static String getRandomStringA (int length ){
Random random = new Random ();
StringBuffer sb = new StringBuffer ();
For (int I = 0; I <length; ++ I ){
Int number = random. nextInt (3 );
Long result = 0;
Switch (number ){
Case 0:
Result = Math. round (Math. random () * 25 + 64 );
Sb. append (String. valueOf (char) result ));
Break;
Case 1:
Result = Math. round (Math. random () * 25 + 97 );
Sb. append (String. valueOf (char) result ));
Break;
Case 2:
Sb. append (String. valueOf (new Random (). nextInt (10 )));
Break;
}
}
Return sb. toString ();
}
}