Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • unique to what, other entries in the table? Commented Dec 7, 2010 at 22:17
  • Checking for that will require a custom function, which over time, will get progressively slower as the pool of available numbers depletes. ie: Generate random #, check table, exists? regenerate, check table, exists?... Commented Dec 7, 2010 at 22:21
  • 2
    If this is for the purposes of generating a unique ID for each row, please use an auto_increment field as per my answer - that's what they're for. :-) Commented Dec 7, 2010 at 22:21
  • @hippout meaning you want a number that is in the given range that is not in a table column? Do you want to track previous outputs as well, i.e. not allow the query to produce the same number later? Commented Dec 7, 2010 at 22:22
  • @middaparka yes auto_increment generates orders in a pre-defined order but the OP asked for a unique random integer. I also have had need for such a number and I used the create-check cycle - but I would prefer a better way. Commented Sep 16, 2015 at 20:06