I guess it is feasible. you will have some hits eventually, especially if
the same pool of random numbers is used accross many tables. There are
several primary key generators available for free that create unique ID's
for you, i would suggest using one of those.
Al
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: jboss <[EMAIL PROTECTED]>
Sent: Tuesday, June 26, 2001 8:54 AM
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