Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Number and Random 2

Status
Not open for further replies.

jeevenze

Technical User
Mar 13, 2001
62
US
I have one of my fields in the table as Data Type as an AutoNumber. For New Values instead of Increment I have it set as Random. This returns random numbers but some of the values returned are negative .
e.g. -2948573. Is there a way that all random numbers returned are absolute or positive?

Any help is much appreciated.
Thank you in advance

Jeevenze.
 
Not using Random Autonumbers. Increment will return all positive values (well, at least for the first 2.1 trillion records!).

If you really need positive random numbers, you'll have to change the data type to Long and write code to generate a random number as you add records. You'll also have to handle the possibility that the random number might be a duplicate, by trying a different random number. Rick Sprague
 
Amen to that!

I feel pretty strongly that you should reserve the Autonumber data type for your primary key generator and leave it set to increment. Who cares since no one should see this?! Then use a random number generator, of which there are many examples, if you really need a random number for a field value.

Pamela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top