On Tue, Jun 26, 2001 at 11:06:42AM -0400, Richard Kasperowski wrote:
> [EMAIL PROTECTED] wrote:
>
> > 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);
>
>
> One problem with using random numbers is that they're not guaranteed to
> be unique--two calls to generateRandomLong() can return the same value.
Yes, but that isn't really a problem because you'll just try again and
it happens sufficiently rarely that the extra time used is
insignificant. At least, that would be the theory.
> Another problem is that computing the next random number might be
> relatively computationally expensive. I'd say serial numbers are better.
If that is so, it would definately be a potential problem. I don't
know much about the effeciency of the Java random number generator
though.
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