-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hal Kaplan
Sent: Thursday, October 26, 2006 1:00 PM
To: [EMAIL PROTECTED]
Subject: RE: random numbers

=> 
=> I have a requirement to assign the products in my database 
=> an id # that is random and has 9 alphanumeric characters.  
=> Thank you Paul Mcnett for the code you posted
=> 
=> on generating passwords.  My question is if I am generating 
=> these random numbers and then I have to check and see if 
=> this number is already in use in the database, how can I 
=> insure that two users are not going to come up with the same 
=> number, then both check and not see it and then both will 
=> save it.  Right now I am assigning IDs but they are 
=> sequential numbers and the last assigned id is kept in a 
=> table and then I lock the table when I increment the ID.  In 
=> the above case even if I lock the table it is not good 
=> enough because read access is still allowed and the query 
=> would still indicate that the string is not in use. 
=> 
=> I hope I am explaining myself well enough.  Does anybody 
=> have any thoughts?  If I use a different seed value for 
=> rand() every time would that guarantee unque numbers.  Ihere 
=> is the code I am using to generate the random string
=> 

You seem to have answered your own question here.

Generate a new id-number.
Lock the table
Verify the new number is unique.  If not, unlock the table and go back to 
beginning.
If the number is unique, add it to the table.
Unlock the table

If the number is actually used, update the record with more fields.
If the number is not actually used, delete the record.

HTH

HALinNY

Thanks I guess I did not think of checking after locking the table only before. 
Thanks a lot.
Judith
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to