|
|
|
Re: Create UNQ Random Number [message #310310 is a reply to message #310208] |
Mon, 31 March 2008 20:57   |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
As ThomasG said, a unique number is by definition NOT random. True randomness (even simulated randomness) will include the possibility of duplicates.
What is your REAL requirement that you are trying to support?
Do you want to avoid index contention with multiple inserts? If so, REVERSE key indexes may be the solution.
Ross Leishman
|
|
|
|
|
|
Re: Create UNQ Random Number [message #312225 is a reply to message #310199] |
Tue, 08 April 2008 04:28   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
You can do this. You need a table with a single column, with a unique constraint on it.
Then your Get_Random function gets a value from dbms_random, and attemtps to insert it into this table. If the insert suceeds, you have a unique randomly generated number.
The performance of this will degrade slowly with the number of random records generated, but that's the price you'll have to pay.
Or, you could select random numbers of a size 7 or 8 orders of magnitude larger than the largest number you're likely to need - this won't guarantee uniqueness, but it will make it very very likely.
|
|
|
|