How to generate a random alpha-numeric string in Java
        Posted  
        
            by Todd
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Todd
        
        
        
        Published on 2008-09-03T02:58:43Z
        Indexed on 
            2010/05/24
            3:31 UTC
        
        
        Read the original article
        Hit count: 343
        
java
I've been looking for a simple java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would "likely" be unique over 500K+ generation (my needs don't really require anything much more sophisticated) . Ideally I would be able to specify a length depending on my uniqueness needs. For example, a generated string of length 12 might look something like "AEYGF7K0DM1X".
Answers: I like @Apocalisp and @erickson's answers equally well. The only downside to @Apocalisp's answer is it requires an apache class. Thanks to both for the help!
© Stack Overflow or respective owner