List:General Discussion« Previous MessageNext Message »
From:Jerry Schwartz Date:May 28 2010 5:47pm
Subject:RE: Using RAND to get a unique ID that has not been used yet
View as plain text  
>-----Original Message-----
>From: Jim Lyons [mailto:jlyons4435@stripped]
>Sent: Friday, May 28, 2010 11:49 AM
>To: Andre Matos
>Cc: mysql@stripped
>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






Thread
Using RAND to get a unique ID that has not been used yetAndre Matos28 May
  • Re: Using RAND to get a unique ID that has not been used yetJim Lyons28 May
    • RE: Using RAND to get a unique ID that has not been used yetSteven Staples28 May
      • Re: Using RAND to get a unique ID that has not been used yetAndre Matos28 May
        • RE: Using RAND to get a unique ID that has not been used yetJerry Schwartz28 May
          • Re: Using RAND to get a unique ID that has not been used yetAndre Matos28 May
    • RE: Using RAND to get a unique ID that has not been used yetJerry Schwartz28 May
  • Re: Using RAND to get a unique ID that has not been used yetPerrin Harkins28 May
  • Re: Using RAND to get a unique ID that has not been used yetKevin \(Gmail\)28 May