Hi ,

can any one tell me how to generate an unique number ?
this can be done in C# with great ease. But i wonder how to generate tat in c++:ooh:

>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".

There is no such thing as a truly unique number, especially in computing. The seed is generally the time.

i am storing some data in the database,
for tat i always need to send a unique value to it,
if the value already exists then an exception will be thrown.
so when ever i am storing in the db the value have to be unique.

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.

What if i run the program again, then again it starts with 1,
so i would get a exception :(

then start at a value 1 more than the highest in the dB, if you wish to use incrementing type indexes. Or you could use the number of microseconds since (e.g.) 12:00am jan 1900 UTC as your 'unique number'.

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 ;)

This article has been dead for over six months. Start a new discussion instead.