By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,038 Members | 1,036 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,038 IT Pros & Developers. It's quick & easy.

How To create a unique number everytime

P: n/a
I need to create a temporary file on the file system. I have over 5000 users

What's the best method to ensure uniqueness

Thank

Bill
Nov 15 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
I need to create a temporary file on the file system. I have over
5000 users.
What's the best method to ensure uniqueness?


Depends on the application. You might get away with just starting at #1.
You might get away with having an array of booleans (or a table of booleans
in a database), one starting at #1 and so on. Or you might have to
generate a random number and keep retrying till you hi one that's not in
use.

It all depends on how often you need to do this, what the load is (are your
5k users concurrent?), and so on.

This can be very fast if you plan it right. If you go the random number
route, use a hige range (ie, a number between 1 and 1,000,000) so that
conflicts are very unlikely.

--
gabriel
Nov 15 '05 #2

P: n/a
Guid myGuid = Guid.NewGuid();
myGuid.ToString(N);

You now have a unique 32-character hex string. Have fun.

Pete

--
http://www.petedavis.net

"gabriel" <no@no--spam.com> wrote in message
news:b8**************************@msgid.meganewsse rvers.com...
I need to create a temporary file on the file system. I have over
5000 users.
What's the best method to ensure uniqueness?
Depends on the application. You might get away with just starting at #1.
You might get away with having an array of booleans (or a table of

booleans in a database), one starting at #1 and so on. Or you might have to
generate a random number and keep retrying till you hi one that's not in
use.

It all depends on how often you need to do this, what the load is (are your 5k users concurrent?), and so on.

This can be very fast if you plan it right. If you go the random number
route, use a hige range (ie, a number between 1 and 1,000,000) so that
conflicts are very unlikely.

--
gabriel

Nov 15 '05 #3

P: n/a
"gabriel" <no@no--spam.com> wrote in message
news:b8**************************@msgid.meganewsse rvers.com...
I need to create a temporary file on the file system. I have over
5000 users. What's the best method to ensure uniqueness?


Guid.NewGuid().ToString()
Nov 15 '05 #4

P: n/a
"Bill" <an*******@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com
I need to create a temporary file on the file system. I have over
5000 users.

What's the best method to ensure uniqueness?


How about
string temppath=System.IO.Path.GetTempFileName();

--
C# newbie... posts are probably inaccurate, inelegant or both

Nov 15 '05 #5

P: n/a
Many THANKS!
Nov 15 '05 #6

P: n/a

Many THANKS
----- Martin Maat wrote: ----

"gabriel" <no@no--spam.com> wrote in messag
news:b8**************************@msgid.meganewsse rvers.com..
I need to create a temporary file on the file system. I have ove

5000 users. What's the best method to ensure uniqueness


Guid.NewGuid().ToString(

Nov 15 '05 #7

P: n/a
Guid.NewGuid() will produce a random GUID. A GUID is a large, unique
hex-based value suitable for database and registry keys.

For example:

Guid myKey = Guid.NewGuid();
Console.WriteLine("New Key: {0}", myKey.ToString());

Hope this helps!

--
----
Doug Erickson [MSFT], Platform SDK UA
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2003 Microsoft Corporation. All rights
reserved.

"gabriel" <no@no--spam.com> wrote in message
news:b8**************************@msgid.meganewsse rvers.com...
I need to create a temporary file on the file system. I have over
5000 users.
What's the best method to ensure uniqueness?
Depends on the application. You might get away with just starting at #1.
You might get away with having an array of booleans (or a table of

booleans in a database), one starting at #1 and so on. Or you might have to
generate a random number and keep retrying till you hi one that's not in
use.

It all depends on how often you need to do this, what the load is (are your 5k users concurrent?), and so on.

This can be very fast if you plan it right. If you go the random number
route, use a hige range (ie, a number between 1 and 1,000,000) so that
conflicts are very unlikely.

--
gabriel

Nov 15 '05 #8

P: n/a
Guid is definitely preferable. If you need a "number" (e.g. 0123456789) you
could
try System.DateTime.Now.Ticks.ToString()
Peter
"Bill" <an*******@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...
I need to create a temporary file on the file system. I have over 5000
users.

What's the best method to ensure uniqueness?

Thanks

Bill

Nov 15 '05 #9

P: n/a
Dear Mr. Styles

Many many thanks. I found your approach to be the safest and easiest

Thank

Bil

----- Bill Styles wrote: ----

"Bill" <an*******@discussions.microsoft.com> wrote in messag
news:B6**********************************@microsof t.com
I need to create a temporary file on the file system. I have ove
5000 users.
What's the best method to ensure uniqueness


How abou
string temppath=System.IO.Path.GetTempFileName()

--
C# newbie... posts are probably inaccurate, inelegant or bot
Nov 15 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.