Multimobile Development: Building Applications for any Smartphone
How To create a unique number everytime
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Bill
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
Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Peter Bromberg [C# MVP] (VIP)
Guid is definitely preferable. If you need a "number" (e.g. 0123456789) you
could
try System.DateTime.Now.Ticks.ToString()
Peter
"Bill" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
gabriel
[Original message clipped]

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
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Pete Davis
Guid myGuid = Guid.NewGuid();
myGuid.ToString(N);

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

Pete

--
http://www.petedavis.net

"gabriel" <Click here to reveal e-mail address> wrote in message
news:b86e7$402ab8f1$437be569$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
Mike
Many THANKS!
Reply to this message...
Vote that this is a GOOD answer...
 
First chapters of Multimobile Development book now available on Apress Alpha program
iPad
 
    
Martin Maat
"gabriel" <Click here to reveal e-mail address> wrote in message
news:b86e7$402ab8f1$437be569$Click here to reveal e-mail address...
[Original message clipped]

Guid.NewGuid().ToString()

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Mike
Many THANKS!
----- Martin Maat wrote: -----

"gabriel" <Click here to reveal e-mail address> wrote in message
news:b86e7$402ab8f1$437be569$Click here to reveal e-mail address...
[Original message clipped]

Guid.NewGuid().ToString()

Reply to this message...
Vote that this is a GOOD answer...
 
New book project – Multimobile Development: Building Applications for any Smartphone
Dive into HTML5
 
    
Doug Erickson [MS] (VIP)
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" <Click here to reveal e-mail address> wrote in message
news:b86e7$402ab8f1$437be569$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Bill Styles
"Bill" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address
[Original message clipped]

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

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

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Bill
Dear Mr. Styles:

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

Thanks

Bill

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

"Bill" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address
[Original message clipped]

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

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

Reply to this message...
Vote that this is a GOOD answer...
 
Steve Jobs’ thoughtful/thought provoking Thoughts on Flash…
Handy list of countries in CSV format
 
 
System.Console
System.DateTime
System.Guid
System.IO.Path




Multimobile Development: Building Applications for any Smartphone
Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734