AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Looking for id/key generator

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> JavaBeans
View previous topic :: View next topic  
Author Message
Igor
Guest





PostPosted: Thu Jul 24, 2003 2:09 pm    Post subject: Looking for id/key generator Reply with quote



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


Back to top
Roy Epperson
Guest





PostPosted: Thu Jul 24, 2003 2:35 pm    Post subject: Re: Looking for id/key generator Reply with quote



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 sb.append(characterMap.charAt(random.nextInt(61)));
}
ans[x] = sb.toString();
}
return ans;
}



"Igor"
Quote:
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





Back to top
Johann Burkard
Guest





PostPosted: Thu Jul 24, 2003 9:25 pm    Post subject: Re: Looking for id/key generator Reply with quote



Igor wrote:

[Please set a Followup-To when posting to multiple groups]

Quote:
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
--
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 (AT) news (DOT) t-online.com>)


Back to top
Steve Horsley
Guest





PostPosted: Thu Jul 24, 2003 9:38 pm    Post subject: Re: Looking for id/key generator Reply with quote

On Thu, 24 Jul 2003 22:06:54 +0200, G wrote:

Quote:
One question.

What if you need not duplicated ids?
Is it enought if you use both timestamp + thread_id ?

Thank you.

Can you be sure the same thread won't hand out 2 nummbers within one
clock-tick (55mS on Win95)?

How about a class that hands out incrementing int values (let it wrap) and
concatenate that int value with the current time. You are unlikely to dish
out 4 billion IDs within 55mS.

Steve

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> JavaBeans All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.