This intrigued me so I just wrote this little program.  Of course it could
be wrapped up in a bean and it needs to check against a list of established
passwords but it gives you upper-lower case random sequence of alpha-numeric
characters. Just feed it the length that you want. It even cleans up after
itself. :0)

public class CraigsRandomizer   {

        // generates a random alpha-numeric sequence

        public static void main(String[] args)  {
                CraigsRandomizer t = new CraigsRandomizer();
                t.randomPass(12); // set to length of 12
        }

        final void randomPass(int len)  {
                int[] random = new int[len];
                int i = 0;
                String result = "";

                while(i < random.length)        {
                        int n = (int)(Math.random() * 122);

                        if (!(n < 49) && (!((n >= 58) && (n <= 64))) && (!((n >= 91) 
&& (n <=
96))))  {
                                random[i] = n;
                                i++;
                        }
                }
                for(int j = 0; j < random.length; j++)  {
                        result += (char)random[j];
                }
                random = null;
                System.out.println(result);
        }
}

Let me know if I can help.

Regards,
Craig O'Brien

Java Programmer/Web Developer


> -----Oryginalna wiadomooeæ-----
> Od: Cato, Christopher [mailto:[EMAIL PROTECTED]]
> Wys³ano: 1 marca 2001 15:05
> Do: '[EMAIL PROTECTED]'
> Temat: Generating a random alphanumeric string
>
>
> Hello, can anyone show me an example or give me a clue about how
> to generate a random alphanumeric string of lets say 16-32 chars?
> TomCat is obviously doing it for the session ids, but how would I
> do the same in a servlet?
>
> Regards,
>
> Christopher Cato
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to