int getUnique() {
static int n = 0;
return ++n;
}
This function is not multithreading safe.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
>this can be done in C# with great ease
Oh good. Show us how you do it in C# so we know what the hell you're talking about by a "unique number".
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
There is no such thing as a truly unique number, especially in computing. The seed is generally the time.
jbennet
Moderator
18,523 posts since Apr 2005
Reputation Points: 1,826
Solved Threads: 601
http://msdn.microsoft.com/en-us/library/system.guid.aspx
A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.
How low of a probability are you looking for?
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
Start your "unique number" at 1 and increment it for each new data record. That seems to be the easiest and safest way to make all your numbers unique.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Never, ever trust in database client program supplied "unique numbers". A well-designed database must have properly defined unique counter fields in its tables and/or correspondent database procedures/triggers.
Let's forget home-made x-"databases" of 80-th ;)
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348