How To create a unique number everytime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Guid myGuid = Guid.NewGuid();
myGuid.ToString(N);

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

Pete
 
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.
 
Bill said:
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();
 
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!

--
 
Guid is definitely preferable. If you need a "number" (e.g. 0123456789) you
could
try System.DateTime.Now.Ticks.ToString()
Peter
 
Dear Mr. Styles

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

Thank

Bil

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

Bill said:
I need to create a temporary file on the file system. I have ove
5000 users.

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