| View previous topic :: View next topic |
| Author |
Message |
Igor Guest
|
Posted: Thu Jul 24, 2003 2:09 pm Post subject: Looking for id/key generator |
|
|
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
|
Posted: Thu Jul 24, 2003 2:35 pm Post subject: Re: Looking for id/key generator |
|
|
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
|
Posted: Thu Jul 24, 2003 9:25 pm Post subject: Re: Looking for id/key generator |
|
|
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
|
Posted: Thu Jul 24, 2003 9:38 pm Post subject: Re: Looking for id/key generator |
|
|
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 |
|
 |
sns Guest
|
Posted: Mon Aug 04, 2003 11:01 pm Post subject: Re: Looking for id/key generator |
|
|
I would like to have the methods you have mentioned . Would appreciate
if you could post it on forum or email it to me.
Thanks
Originally posted by Roy Epperson
| 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 wrote in message
news:JMRTa.65430$zwL.48820 (AT) news04 (DOT) bloor.is.net.cable.rogers.c-
om"]news:JMRTa.65430$zwL.48820 (AT) news04 (DOT) bloor.is.net.cable.rogers.com-
[/url]...
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
|
--
Posted via http://dbforums.com
|
|
| Back to top |
|
 |
sns Guest
|
Posted: Thu Aug 07, 2003 5:17 pm Post subject: Re: Looking for id/key generator |
|
|
Originally posted by sns
| Quote: |
Roy,
I would like to have the methods you have mentioned . Would appreciate
if you could post it on forum or email it to me.
Thanks |
--
Posted via http://dbforums.com
|
|
| Back to top |
|
 |
|