My thoughts..

on what I work on

Generating Random Strings using RandomStringUtils

Posted by psiva on August 21, 2007

If you want to generate random strings for assigning passwords or for creating a captcha, consider using RandomStringUtils class from commons-lang package.

It enables to generate a random string of a specified length, enables you to choose the set of characters to be used to generate the string besides giving us an option whether to include numbers in the string or not.

RandomStringUtils.random(8) would generate a random string of length 8.

RandomStringUtils.random(8, true,true) would generate a random string of length 8 and includes numbers and characters as a part of the string.

RandomStringUtils.random(4, {a,b,c,d,e,f,x}) would generate a random string of length 4 from the characters of the character array .

RandomStringUtils.randomAlphaNumeric(5) would generate a randomĀ  alphanumberic string of length 5.

About these ads

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: