A similar technique is to do something like concat your content, then use
the string.hashCode function to get a hashcode. fairly well distributed,
easily repeatable... etc etc. :)

Al

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 26, 2001 9:28 AM
Subject: RE: [JBoss-user] Key generation by random numbers


> Well... I use similar technique for generating unique IDs, but I utilize
the
> MD5 hash function. It is believed that it provides enough uniqueness. The
> only problem is that you cannot use the long as primary key field (in my
> case I use String). But you may convert 128-bit digest into 2x64-bit
longs.
>
> It has similar pros and cons, however the max value is now 2^128 which is
> quite large number :).
>
> Regards,
> Roman.
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > Sent: Dienstag, 26. Juni 2001 14:54
> > To: jboss
> > Subject: [JBoss-user] Key generation by random numbers
> >
> >
> > As a follow-up to the debate on how to get auto-increment primary
> > keys:
> >
> > Is it feasible to use a random number generator to generate primary
> > keys? I don't really need my records to have steadily increasing keys
> > and my number of records will presumably be much smaller than the size
> > of my value space (4 billion? depending on data type for prim-key). So
> > if I do something along the following when making a new record;
> >
> > boolean created = false;
> > do
> > {
> >    Long key = generateRandomLong();
> >    created = ejb.create(key, contents);
> > }
> > while (!created);
> >
> >
> > (here, ejb.create() takes the primary key of the new record as its
> > first param and returns true if success, false if not success)
> >
> > My theory is that most of the time, the creation will succeed on the
> > first attempt, based on the assumption that number of records is
> > insignificant compared to the value space of Long.
> >
> > Pros:
> > I don't need to do manual synchronisation with a central
> > key-generating bean.
> > I don't need to do DB-specific calls to get it to generate for me.
> >
> > Cons:
> > Unpredictable time use for creation.
> > Unusable if number of records becomes significant compared to value
> > space of Long.
> >
> > I am assuming also that the creation of a random Long is a fast
> > process.
> >
> > Cheers
> > Bent D
> > --
> > Bent Dalager - [EMAIL PROTECTED] - http://www.pvv.org/~bcd
> >                                     powered by emacs
> >
> > _______________________________________________
> > JBoss-user mailing list
> > [EMAIL PROTECTED]
> > http://lists.sourceforge.net/lists/listinfo/jboss-user
> >
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to