473,468 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Create 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 11538
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.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
"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
"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
Many THANKS!
Nov 15 '05 #6

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
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...
3
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...
8
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
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
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...
2
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" &...
1
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...
6
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 ...
13
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.