[EMAIL PROTECTED] wrote:

> 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.


But what if it's not sufficiently rare?  In the worst case, it will take 
O(n) time to find the next usable random number.  You might as well just 
use a serial number; it will always take O(1) time to find the next 
usable serial number.

-- 
Richard Kasperowski (mailto:[EMAIL PROTECTED])
Tel: 617-576-1552, Fax: 617-576-2441
http://www.altisimo.com/


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

Reply via email to