Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to select just alphanumeric random choices from an ASCII table?

Status
Not open for further replies.

royboy75

Programmer
Feb 13, 2007
114
0
0
GB
Hello,

I need to create a java application which generates random passwords.
I am half way through but what I can't accomplish is select only alphanumeric choices from the ascii table (meaning between 48 and 57 for digits and between 97 and 122 for letters).
Can someone please help?
 
Code:
char[] chars = new char[]{'a','b','c','d','e','f','g' ..etc};
//use a random index to select characters

Tim
 
Hi tim,

Thanks for the quick answer.
I prefer using the next() method of Rand.
Is there any way to limit it to this range?
 
You can use Character.isLetter to discrimine the results.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top