473,785 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To create a unique number everytime

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
9 11562
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
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.megan ewsservers.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
"gabriel" <no@no--spam.com> wrote in message
news:b8******** *************** ***@msgid.megan ewsservers.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
"Bill" <an*******@disc ussions.microso ft.com> wrote in message
news:B6******** *************** ***********@mic rosoft.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.GetTem pFileName();

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

Nov 15 '05 #5
Many THANKS!
Nov 15 '05 #6

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

"gabriel" <no@no--spam.com> wrote in messag
news:b8******** *************** ***@msgid.megan ewsservers.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
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.WriteLi ne("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.megan ewsservers.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
Guid is definitely preferable. If you need a "number" (e.g. 0123456789) you
could
try System.DateTime .Now.Ticks.ToSt ring()
Peter
"Bill" <an*******@disc ussions.microso ft.com> wrote in message
news:B6******** *************** ***********@mic rosoft.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
Dear Mr. Styles

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

Thank

Bil

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

"Bill" <an*******@disc ussions.microso ft.com> wrote in messag
news:B6******** *************** ***********@mic rosoft.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.GetTem pFileName()

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4484
by: Joe Wong | last post by:
Hi, I need to implement a unique number generator that 1 or more processes on same or different machines will make use of it. Is there any library / project available already for this? Thanks in advance, -- Wong
3
8260
by: Dixie | last post by:
I am trying to create a registration system in which a unique text string accessible in a table of the program is turned into a unique number which will be matched with a number sent to the customer to type into the program to reregister it. The idea is that this key will not work on another program, only the one it is generated for. My initial problem is how do I generate in code, a unique number from say a 3 word phrase with only...
8
2125
by: Abhishek | last post by:
Hi! I need to create a unique password everytime i click a button . what technique/Algo should i follow. Abhishek
5
8364
by: David Pope | last post by:
I need to create a unique number like a GUID but all numbers. Does anyone know of algorithm to do this? Thanks, David
4
2967
by: David Dvali | last post by:
Hello. How can I generate some fixed length unique number (for example 6 character) based on some number like 1, 2, .. 45, 46, 47 (Generally I will use unique ID of the database record as base number)? Thank you.
2
1542
by: nickyazura | last post by:
Hi, I would like to ask you regarding creating file name by adding unique number where it can automatically generated Dim sFileE As String sFileE = ".csv" sFileName = "Weld_In_Record" & Format(Now, "yyyymmdd") & sFileE after run, i can get a result of Weld_In_Record20080304.csv here, i want to add more by putting other sequential unique number
1
1468
by: ramdil | last post by:
Hi All I have got a lots of help from this forum and again i am in need of yours help. I will briefly explain the scenario.I have a customer table.It was created 12 years ago and its Primary key is Text value..And users was entering the customercode in their own.But now they are asking me to autogenerate it.Since its datatype is text, i cant use autonumber as i cant change the datatype. So what i am trying to do is to generate a unique...
6
4321
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B Alvin Leader
13
8109
by: Scott Kaempfe | last post by:
I need to identify parts we buy at our plant. I want to give each a unique serial number that is based on the date. We may have multiple parts on a given date so I want to have the unique serial number in the format: MMDDYY-XXX where XXX is a unique number that start with 001 for the first item of the day. 002 for the second, etc. but starting over the next day. When a user enters info in the database, it may already have a number. If...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.