here is code that I tried out for generating a user id using the user name

I have to pass a string and it returns a 8 digit alpha numeric

Hope it helps,

 

public static String getCode(String text){

String code = "";

 

text = text.trim();

if(text.length()<1){

return null;

}

text = text.toUpperCase();

if(random==null){

random = new java.util.Random();

}

String code_temp = "";

int no_of_chars = 3 ; //not of chars from text

for(int i=0;i<no_of_chars;i++){

code_temp =

String.valueOf(text.charAt(random.nextInt(text.length())));

if(code_temp.equals(" ")){

i--;

}else{

code = code + code_temp;

}

}

code = code + java.lang.String.valueOf(random.nextInt(10000));

java.util.Date date = new java.util.Date();

code = code + java.lang.String.valueOf(date.getDate());

}catch(Exception e){

return null;

}

return code;

}

 

 

 

 

Regards,
Vikramjit Singh.


 -----Original Message-----
From: Anoop Kumar V [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 26, 2002 12:26 AM
To: [EMAIL PROTECTED]
Subject: Random string

Hi,
this is offtopic, and i am sorry .. but i hv a servlet here which resets users passwords in case they hv
forgotten them. Is there someway i can generate random strings of length say 6 characters long.
 
again sorry,
-anoop

Reply via email to