Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / July 2003

Tip: Looking for answers? Try searching our database.

Looking for id/key generator

Thread view: 
Igor - 24 Jul 2003 15:09 GMT
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>)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.