473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Numbers Question!

what's the best way of getting unique numbers when requested other than
creating GUIDs? Right now this is what I am doing but I am not very happy
with it.
Random rnd=new Random((int)System.DateTime.Now.Ticks);
int unique=rnd.Next();

TIA

--
========
Regards
Vai
========
Nov 15 '05 #1
13 1216
Hi Vai

What are these numbers for? Are they for records in a database? What is
wrong with a Guid?

Gary

"Vai2000" <va*@onebox.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
what's the best way of getting unique numbers when requested other than
creating GUIDs? Right now this is what I am doing but I am not very happy
with it.
Random rnd=new Random((int)System.DateTime.Now.Ticks);
int unique=rnd.Next();

TIA

--
========
Regards
Vai
========

Nov 15 '05 #2

"Vai2000" <va*@onebox.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
what's the best way of getting unique numbers when requested other than
creating GUIDs? Right now this is what I am doing but I am not very happy
with it.
Random rnd=new Random((int)System.DateTime.Now.Ticks);
int unique=rnd.Next();

TIA

--
========
Regards
Vai
========


Hi,

A random number is NOT unique! It is unpredictable (that's what "random"
means :-) ) but it is possible to get duplicate values.

Hans Kesting
Nov 15 '05 #3
Unfortunately I need this value for creating unique numerical ID (Its part
of a naming convention) - I don't have access to DB!!

Thanks
"Gary van der Merwe" <ga*****@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
Hi Vai

What are these numbers for? Are they for records in a database? What is
wrong with a Guid?

Gary

"Vai2000" <va*@onebox.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
what's the best way of getting unique numbers when requested other than
creating GUIDs? Right now this is what I am doing but I am not very happy with it.
Random rnd=new Random((int)System.DateTime.Now.Ticks);
int unique=rnd.Next();

TIA

--
========
Regards
Vai
========


Nov 15 '05 #4
Do you have any way of determining the names allready created?

"Vai2000" <no****@microsoft.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
Unfortunately I need this value for creating unique numerical ID (Its part
of a naming convention) - I don't have access to DB!!

Thanks
"Gary van der Merwe" <ga*****@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
Hi Vai

What are these numbers for? Are they for records in a database? What is
wrong with a Guid?

Gary

"Vai2000" <va*@onebox.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
what's the best way of getting unique numbers when requested other than creating GUIDs? Right now this is what I am doing but I am not very happy with it.
Random rnd=new Random((int)System.DateTime.Now.Ticks);
int unique=rnd.Next();

TIA

--
========
Regards
Vai
========



Nov 15 '05 #5
"Vai2000" <va*@onebox.com> wrote in
news:#M**************@TK2MSFTNGP10.phx.gbl:
what's the best way of getting unique numbers when requested
other than creating GUIDs?


Use a linear series: 1, 2, 3, etc...
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 15 '05 #6
No
"Gary van der Merwe" <ga*****@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Do you have any way of determining the names allready created?

"Vai2000" <no****@microsoft.com> wrote in message
news:ul**************@TK2MSFTNGP10.phx.gbl...
Unfortunately I need this value for creating unique numerical ID (Its part
of a naming convention) - I don't have access to DB!!

Thanks
"Gary van der Merwe" <ga*****@hotmail.com> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
Hi Vai

What are these numbers for? Are they for records in a database? What is wrong with a Guid?

Gary

"Vai2000" <va*@onebox.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> what's the best way of getting unique numbers when requested other

than > creating GUIDs? Right now this is what I am doing but I am not very

happy
> with it.
>
>
> Random rnd=new Random((int)System.DateTime.Now.Ticks);
> int unique=rnd.Next();
>
> TIA
>
> --
> ========
> Regards
> Vai
> ========
>
>



Nov 15 '05 #7
Could you please elaborate a little more? basically I don't have any
knowledge of my last number, so how can I ensure a linear number?

Thanks
PS: Ways I can think would be registry etc to maintain a starting seed and
then increment it everytime.

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Vai2000" <va*@onebox.com> wrote in
news:#M**************@TK2MSFTNGP10.phx.gbl:
what's the best way of getting unique numbers when requested
other than creating GUIDs?


Use a linear series: 1, 2, 3, etc...
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 15 '05 #8
"Vai2000" <no****@microsoft.com> wrote in
news:ue**************@TK2MSFTNGP09.phx.gbl:
Could you please elaborate a little more? basically I don't have
any knowledge of my last number, so how can I ensure a linear
number?

Thanks
PS: Ways I can think would be registry etc to maintain a
starting seed and then increment it everytime.


If you can somehow save (or find out) the value of the last number
used in the series, then it should be simple:

number is requested
get value of most recently used number (from a data store)
increment number
store new number value in the data store
return number

Multi-user and multi-threaded access should be planned for. The
above pseudo-code should be be "locked" somehow so only one
thread/user can access it at a time. With threads, the "lock"
statement can be used. With databases, the code can be wrapped in a
transaction, or the isolation level can be set to serial access.
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 15 '05 #9
You still haven't answered Garys original question. Whats wrong with a Guid
? This is the most reliable and easy way of generating a unique (to all
practical purposes) number on any computer without a complex error prone
tracking system.

Cheers

Doug Forster

"Vai2000" <no****@microsoft.com> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...
Could you please elaborate a little more? basically I don't have any
knowledge of my last number, so how can I ensure a linear number?

Thanks
PS: Ways I can think would be registry etc to maintain a starting seed and
then increment it everytime.

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"Vai2000" <va*@onebox.com> wrote in
news:#M**************@TK2MSFTNGP10.phx.gbl:
what's the best way of getting unique numbers when requested
other than creating GUIDs?


Use a linear series: 1, 2, 3, etc...
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/


Nov 15 '05 #10
Well I need a number as to a GUID which is a combination of number and
alphabets!

TIA

"Doug Forster" <doug_ZAPTHIS_AT_TONIQ_ZAPTHIS_co.nz> wrote in message
news:uw**************@TK2MSFTNGP12.phx.gbl...
You still haven't answered Garys original question. Whats wrong with a Guid ? This is the most reliable and easy way of generating a unique (to all
practical purposes) number on any computer without a complex error prone
tracking system.

Cheers

Doug Forster

"Vai2000" <no****@microsoft.com> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...
Could you please elaborate a little more? basically I don't have any
knowledge of my last number, so how can I ensure a linear number?

Thanks
PS: Ways I can think would be registry etc to maintain a starting seed and then increment it everytime.

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:Xn**********************************@207.46.2 48.16...
"Vai2000" <va*@onebox.com> wrote in
news:#M**************@TK2MSFTNGP10.phx.gbl:

> what's the best way of getting unique numbers when requested
> other than creating GUIDs?

Use a linear series: 1, 2, 3, etc...
Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/



Nov 15 '05 #11
No a Guid is really a 16 byte number. You are thinking of the common hex
representation of a Guid. Use ToByteArray() and then you can represent it
however you like. Perhaps you could even 'condense' it at the risk of
reducing uniqueness.

Cheers

Doug Forster

"Vai2000" <va*@onebox.com> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
Well I need a number as to a GUID which is a combination of number and
alphabets!

TIA

"Doug Forster" <doug_ZAPTHIS_AT_TONIQ_ZAPTHIS_co.nz> wrote in message
news:uw**************@TK2MSFTNGP12.phx.gbl...
You still haven't answered Garys original question. Whats wrong with a

Guid
? This is the most reliable and easy way of generating a unique (to all
practical purposes) number on any computer without a complex error prone
tracking system.

Cheers

Doug Forster

"Vai2000" <no****@microsoft.com> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...
Could you please elaborate a little more? basically I don't have any
knowledge of my last number, so how can I ensure a linear number?

Thanks
PS: Ways I can think would be registry etc to maintain a starting seed and then increment it everytime.

"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message news:Xn**********************************@207.46.2 48.16...
> "Vai2000" <va*@onebox.com> wrote in
> news:#M**************@TK2MSFTNGP10.phx.gbl:
>
> > what's the best way of getting unique numbers when requested
> > other than creating GUIDs?
>
> Use a linear series: 1, 2, 3, etc...
>
>
> Chris.
> -------------
> C.R. Timmons Consulting, Inc.
> http://www.crtimmonsinc.com/



Nov 15 '05 #12
Great!!
"Doug Forster" <doug_ZAPTHIS_AT_TONIQ_ZAPTHIS_co.nz> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
No a Guid is really a 16 byte number. You are thinking of the common hex
representation of a Guid. Use ToByteArray() and then you can represent it
however you like. Perhaps you could even 'condense' it at the risk of
reducing uniqueness.

Cheers

Doug Forster

"Vai2000" <va*@onebox.com> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
Well I need a number as to a GUID which is a combination of number and
alphabets!

TIA

"Doug Forster" <doug_ZAPTHIS_AT_TONIQ_ZAPTHIS_co.nz> wrote in message
news:uw**************@TK2MSFTNGP12.phx.gbl...
You still haven't answered Garys original question. Whats wrong with a

Guid
? This is the most reliable and easy way of generating a unique (to all practical purposes) number on any computer without a complex error prone tracking system.

Cheers

Doug Forster

"Vai2000" <no****@microsoft.com> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...
> Could you please elaborate a little more? basically I don't have any
> knowledge of my last number, so how can I ensure a linear number?
>
> Thanks
> PS: Ways I can think would be registry etc to maintain a starting
seed and
> then increment it everytime.
>
> "Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in

message
> news:Xn**********************************@207.46.2 48.16...
> > "Vai2000" <va*@onebox.com> wrote in
> > news:#M**************@TK2MSFTNGP10.phx.gbl:
> >
> > > what's the best way of getting unique numbers when requested
> > > other than creating GUIDs?
> >
> > Use a linear series: 1, 2, 3, etc...
> >
> >
> > Chris.
> > -------------
> > C.R. Timmons Consulting, Inc.
> > http://www.crtimmonsinc.com/
>
>



Nov 15 '05 #13
You can also use a SecureRandom to generate better random numbers. Decide
how often you are willing to have numbers collide, on average, and take
enough bits to ensure this.

If you aren't willing to have any collisions ever, you need to add a check
for uniqueness.

"Doug Forster" <doug_ZAPTHIS_AT_TONIQ_ZAPTHIS_co.nz> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
No a Guid is really a 16 byte number. You are thinking of the common hex
representation of a Guid. Use ToByteArray() and then you can represent it
however you like. Perhaps you could even 'condense' it at the risk of
reducing uniqueness.

Cheers

Doug Forster

"Vai2000" <va*@onebox.com> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
Well I need a number as to a GUID which is a combination of number and
alphabets!

TIA

"Doug Forster" <doug_ZAPTHIS_AT_TONIQ_ZAPTHIS_co.nz> wrote in message
news:uw**************@TK2MSFTNGP12.phx.gbl...
You still haven't answered Garys original question. Whats wrong with a

Guid
? This is the most reliable and easy way of generating a unique (to all practical purposes) number on any computer without a complex error prone tracking system.

Cheers

Doug Forster

"Vai2000" <no****@microsoft.com> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl...
> Could you please elaborate a little more? basically I don't have any
> knowledge of my last number, so how can I ensure a linear number?
>
> Thanks
> PS: Ways I can think would be registry etc to maintain a starting
seed and
> then increment it everytime.
>
> "Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in

message
> news:Xn**********************************@207.46.2 48.16...
> > "Vai2000" <va*@onebox.com> wrote in
> > news:#M**************@TK2MSFTNGP10.phx.gbl:
> >
> > > what's the best way of getting unique numbers when requested
> > > other than creating GUIDs?
> >
> > Use a linear series: 1, 2, 3, etc...
> >
> >
> > Chris.
> > -------------
> > C.R. Timmons Consulting, Inc.
> > http://www.crtimmonsinc.com/
>
>



Nov 15 '05 #14

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

Similar topics

9
by: freddy | last post by:
how can I display a set of numbers like this: 1 2 3 4 5 6 ... instead of this 1 2 3 4 5 ....
19
by: Eduardo Bezerra | last post by:
Hi, I'm looking for an efficient way to create the oposite of a list of numbers. For example, suppose I have this list of numbers: 100 200 300
16
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
8
by: Arun Bhalla | last post by:
Hi, I'm developing an Explorer bar using VS.NET 2003 (C#) on Windows XP. For some time, I've noticed that I don't have filenames and line numbers appearing in my exceptions' stack traces. On...
11
by: Leon | last post by:
I have six textbox controls on my webform that allows the user to enter any numbers from 1 to 25 in any order. However, I would like to sort those numbers from least to greatest before sending them...
17
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
45
by: bobalong | last post by:
Hi I'm have some problem understanding how JS numbers are represented internally. Take this code for an example of weirdness: var biggest = Number.MAX_VALUE; var smaller = Number.MAX_VALUE...
10
by: Dave Cox | last post by:
of "int" in VB? //b=1.2 b=int(b) //b now equals 1
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.