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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unique Random Number Generator

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
0
0
IN
Guys,

Does anyone have a simple [red]UNIQUE[/red] random number generator function(VB function)?

Thanks in advance.

-DNG
 
How unique? Unique in the sense that it will never be given out again no matter how many time the function is called or unique in the sense that it will return a unique number between 1 and 10 (for example)?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
the first one..."that it will never be given out again no matter how many time the function is called"

Thanks

-DNG
 
Maybe, it's better if you explain why you need this number as I can suggest things but they may not be appropiate (my current thinking is that a GUID may work for you but this may not be the case).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
instead of using the indentity autonumber in my sql server...i thought creating a 5 digit unique random number for each record inserted into my database...and i wanted it to be unique because i am making it the primary key in the table...

-DNG
 
yeah...i guess it is better to go with the identity column instead of some unique random number(which might not ideally be unique all the times :) )

Thanks Guys

-DNG
 
Go with the Identity column.

Just don't base any business logic on it's value -- it's only there to allow other tables to reference it as a foreign key.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Yep, I'll third the identity column! It doesn't (and shouldn't) matter what it's value is as long as it is unique.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I second the suggestion of using GUIDs for unique identifiers.

Identity columns are OK if you will NEVER need to merge data from two instances of the same database, but since "never" never holds true (heh, heh) I now always use GUIDs. Using GUIDs means two records will never have the same ID no matter what database they are in.

I also suggest using an identify column for a human readable (and probably unique) number.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top