This is something I wrote,
it should do the trick...


# BEGIN FILE RndStringGen.java


public final class RndStringGen {

        private String rndstring;

        public static void main (String [] args) {
                // Create Object, call getPasswd and pring the password
                // Call getPasswd with as argument the number of chars          // you 
want
in password

                System.out.println(new RndStringGen().getPasswd(8));

        } //

        public String getPasswd(int length) {

                StringBuffer strbuf = new StringBuffer(length);


                for (int counter=0; counter<length; counter++) {
                        int i = (int) (1230 / 9  * Math.random());

                        /* Check for Bounderies to have nice characters
above 50, less then 123, and excluding a list of 'annoying characters.
*/

                        if (i<50) {
                                i+=50;
                        }
                        else {
                                if (i>123) {
                                        i -=19;
                                }
                        } // if

                        // append character to String, and rerun the
loop
                        strbuf.append((char)i);
                } //for

                return strbuf.toString();
        }//getPasswd


}//class





# END FILE





On Wed, 2002-06-26 at 09:25, Anoop Kumar V wrote:
> 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

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to