>-----Original Message----- >From: Jim Lyons [mailto:jlyons4...@gmail.com] >Sent: Friday, May 28, 2010 11:49 AM >To: Andre Matos >Cc: mysql@lists.mysql.com >Subject: Re: Using RAND to get a unique ID that has not been used yet > >If your specs are that specific (IDs must be between 1 and 999999) >then you could create a 999999-row table with one integer column and >prefill it with the numbers 1 to 999999 in random order. > >Then you could write a function that would select and return the first >number in the table, then delete that record so you would not reuse >it. > >Once you've done the work of sorting 999999 numbers in random order >(which can be done anywhich way) it's easy and you don't have to loop >an indeterminant number of times. You would be looping an increasing >number of times as you begin to fill up the table. > [JS] You don't have to go to the trouble of sorting the "number" table in any order, random or anything else. Just select a random record from that table. Since you'll have the number of that record, you can delete it.
Regards, Jerry Schwartz Global Information Incorporated 195 Farmington Ave. Farmington, CT 06032 860.674.8796 / FAX: 860.674.8341 www.the-infoshop.com -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/mysql?unsub=arch...@jab.org