Hi all,
I am looking for an ID/key generator in Java. It can be a class or a
package.
I need the result to be something like 2AF33Y88 - digits and letters
together.
It can be fixed size or I have to set the length.
Thanks in advance,
Igor
Roy Epperson - 24 Jul 2003 15:35 GMT
Here's a portion of a class I wrote to generate keys. I also have a method
to reject offensive words and fragments of words and a method that look into
a table of already generated keys to insure the new key is unique. Let me
know privately if you're interested in those.
private static final String characterMap =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static String[] generate(int randomStringLength, int
numberOfStrings, Random random){
String ans[] = new String[numberOfStrings];
for(int x= 0; x < numberOfStrings; x++){
StringBuffer sb = new StringBuffer();
for(int n = 0; n <randomStringLength; n++){
sb.append(characterMap.charAt(random.nextInt(61)));
}
ans[x] = sb.toString();
}
return ans;
}
> Hi all,
>
[quoted text clipped - 6 lines]
> Thanks in advance,
> Igor
Johann Burkard - 24 Jul 2003 22:25 GMT
[Please set a Followup-To when posting to multiple groups]
> I am looking for an ID/key generator in Java. It can be a class or a
> package.
> I need the result to be something like 2AF33Y88 - digits and letters
> together.
If you need unique keys, I implemented the UUID/GUID specification once,
it's at http://johannburkard.de/misc/uuid.zip.
If you need "safe" passwords, check out
http://johannburkard.de/misc/PasswordTools.java.
Johann

Signature
Fühle dich bitte nicht auf die Füsse getreten wenn ich dir sage, dass du
mit dem Niveau der meisten hier° nicht mithalten kannst. Du lieferst
Steil-vorlagen wie ein Troll. Allerliebst. (*Tönnes über mich in
<bcdlqr$aul$04$4@news.t-online.com>)