Guid.Empty

  • Thread starter Thread starter Rene
  • Start date Start date
R

Rene

I am using the Guid.Empty value ("00000000-0000-0000-0000-000000000000") to
represent a special meaning. The problem is that I don't know if there is a
chance that a command like "Guid.NewGuid()"would generate a Guid.Empty value
could this be possible or is the "00000000-0000-0000-0000-000000000000" Guid
reserved or something like that?

Thank you.
 
Rene said:
I am using the Guid.Empty value ("00000000-0000-0000-0000-000000000000") to represent a special meaning. The problem is that I
don't know if there is a chance that a command like "Guid.NewGuid()"would generate a Guid.Empty value could this be possible or is
the "00000000-0000-0000-0000-000000000000" Guid reserved or something like that?


Why not use a custom GUID for your special meaning?
The chances of a collision with some other GUID are
very very small. Remember, that low probability is
the whole reason GUID are in common use.
 
[top-posting maintained for inclarity]

To maximize the probability of a collision with some other
non-randomly generated "GUID", you could not choose
a better value than the one you propose.
 
All I really want to know is what are the chances that Guid.NewGuid() will
create a 00000000-0000-0000-0000-000000000000 value? What would it take for
the function to create such value?


Larry Brasfield said:
[top-posting maintained for inclarity]

To maximize the probability of a collision with some other
non-randomly generated "GUID", you could not choose
a better value than the one you propose.

--
--Larry Brasfield
email: (e-mail address removed)
Above views may belong only to me.

Rene said:
"00000000-0000-0000-0000-000000000000" is in fact my custom Guid.
 
Guid.NewGuid() will return a string of zeros exactly as often as it will
return the value: {2C948FCC-035F-4a98-866E-4C9DF5FA7984}... which is very
remote indeed.

However, another developer may make the same mistake you are making, and
assume that their app is not running on the same machine as your app, and
that therefore, a string of zeros is a safe number. Statistically speaking,
that condition is far more likely than the possibility of Guid.NewGuid()
creating a duplicate number.

You are MUCH better off simply generating a GUID and using it. Then, you
are less likely to run into another programmer with a penchant for guessing
a random number.

This is precisely what Larry was trying to say.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Rene said:
All I really want to know is what are the chances that Guid.NewGuid() will
create a 00000000-0000-0000-0000-000000000000 value? What would it take
for the function to create such value?


Larry Brasfield said:
[top-posting maintained for inclarity]

To maximize the probability of a collision with some other
non-randomly generated "GUID", you could not choose
a better value than the one you propose.

--
--Larry Brasfield
email: (e-mail address removed)
Above views may belong only to me.

Rene said:
"00000000-0000-0000-0000-000000000000" is in fact my custom Guid.

message I am using the Guid.Empty value
("00000000-0000-0000-0000-000000000000") to represent a special
meaning. The problem is that I don't know if there is a chance that a
command like "Guid.NewGuid()"would generate a Guid.Empty value could
this be possible or is the "00000000-0000-0000-0000-000000000000" Guid
reserved or something like that?


Why not use a custom GUID for your special meaning?
The chances of a collision with some other GUID are
very very small. Remember, that low probability is
the whole reason GUID are in common use.
 
Thanks Nick.



I understood what Larry was saying, I was more curious than anything else,
you see, as you know, the Guid has a specific property called Empty that
represents the 0000...., that's why I was thinking that maybe the 0000....
was reserved for that special purpose (kind of like null in databases to
represent nothing) and it was impossible to get it though Guid.NewGuid().



Plain curiosity.




Nick Malik said:
Guid.NewGuid() will return a string of zeros exactly as often as it will
return the value: {2C948FCC-035F-4a98-866E-4C9DF5FA7984}... which is very
remote indeed.

However, another developer may make the same mistake you are making, and
assume that their app is not running on the same machine as your app, and
that therefore, a string of zeros is a safe number. Statistically
speaking, that condition is far more likely than the possibility of
Guid.NewGuid() creating a duplicate number.

You are MUCH better off simply generating a GUID and using it. Then, you
are less likely to run into another programmer with a penchant for
guessing a random number.

This is precisely what Larry was trying to say.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Rene said:
All I really want to know is what are the chances that Guid.NewGuid()
will create a 00000000-0000-0000-0000-000000000000 value? What would it
take for the function to create such value?


Larry Brasfield said:
[top-posting maintained for inclarity]

To maximize the probability of a collision with some other
non-randomly generated "GUID", you could not choose
a better value than the one you propose.

--
--Larry Brasfield
email: (e-mail address removed)
Above views may belong only to me.

"00000000-0000-0000-0000-000000000000" is in fact my custom Guid.

message I am using the Guid.Empty value
("00000000-0000-0000-0000-000000000000") to represent a special
meaning. The problem is that I don't know if there is a chance that a
command like "Guid.NewGuid()"would generate a Guid.Empty value could
this be possible or is the "00000000-0000-0000-0000-000000000000" Guid
reserved or something like that?


Why not use a custom GUID for your special meaning?
The chances of a collision with some other GUID are
very very small. Remember, that low probability is
the whole reason GUID are in common use.
 
Shouldn't a completely zero guid be impossible to get from Guid.NewGuid() as
between the variant and version fields there ought to be at least one bit
set? Or am I mistaken in thinking Guids follow a standard format
(http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt)?
I don't argue the point that Guid.Empty should be used with care to avoid
collision due to its being used as a sentinel by other developers, but I
don't think you should need to worry about it colliding with
machine-generated values.
Just curious.

Nick Malik said:
Guid.NewGuid() will return a string of zeros exactly as often as it will
return the value: {2C948FCC-035F-4a98-866E-4C9DF5FA7984}... which is very
remote indeed.

However, another developer may make the same mistake you are making, and
assume that their app is not running on the same machine as your app, and
that therefore, a string of zeros is a safe number. Statistically speaking,
that condition is far more likely than the possibility of Guid.NewGuid()
creating a duplicate number.

You are MUCH better off simply generating a GUID and using it. Then, you
are less likely to run into another programmer with a penchant for guessing
a random number.

This is precisely what Larry was trying to say.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Rene said:
All I really want to know is what are the chances that Guid.NewGuid() will
create a 00000000-0000-0000-0000-000000000000 value? What would it take
for the function to create such value?


Larry Brasfield said:
[top-posting maintained for inclarity]

To maximize the probability of a collision with some other
non-randomly generated "GUID", you could not choose
a better value than the one you propose.

--
--Larry Brasfield
email: (e-mail address removed)
Above views may belong only to me.

"00000000-0000-0000-0000-000000000000" is in fact my custom Guid.

message I am using the Guid.Empty value
("00000000-0000-0000-0000-000000000000") to represent a special
meaning. The problem is that I don't know if there is a chance that a
command like "Guid.NewGuid()"would generate a Guid.Empty value could
this be possible or is the "00000000-0000-0000-0000-000000000000" Guid
reserved or something like that?


Why not use a custom GUID for your special meaning?
The chances of a collision with some other GUID are
very very small. Remember, that low probability is
the whole reason GUID are in common use.
 
My mistake. You are correct. an all-zero GUID is not possible from
Guid.NewGuid().

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Jeremy Davis said:
Shouldn't a completely zero guid be impossible to get from Guid.NewGuid()
as
between the variant and version fields there ought to be at least one bit
set? Or am I mistaken in thinking Guids follow a standard format
(http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt)?
I don't argue the point that Guid.Empty should be used with care to avoid
collision due to its being used as a sentinel by other developers, but I
don't think you should need to worry about it colliding with
machine-generated values.
Just curious.

Nick Malik said:
Guid.NewGuid() will return a string of zeros exactly as often as it will
return the value: {2C948FCC-035F-4a98-866E-4C9DF5FA7984}... which is very
remote indeed.

However, another developer may make the same mistake you are making, and
assume that their app is not running on the same machine as your app, and
that therefore, a string of zeros is a safe number. Statistically
speaking,
that condition is far more likely than the possibility of Guid.NewGuid()
creating a duplicate number.

You are MUCH better off simply generating a GUID and using it. Then, you
are less likely to run into another programmer with a penchant for
guessing
a random number.

This is precisely what Larry was trying to say.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Rene said:
All I really want to know is what are the chances that Guid.NewGuid()
will
create a 00000000-0000-0000-0000-000000000000 value? What would it take
for the function to create such value?


message
[top-posting maintained for inclarity]

To maximize the probability of a collision with some other
non-randomly generated "GUID", you could not choose
a better value than the one you propose.

--
--Larry Brasfield
email: (e-mail address removed)
Above views may belong only to me.

"00000000-0000-0000-0000-000000000000" is in fact my custom Guid.

message I am using the Guid.Empty value
("00000000-0000-0000-0000-000000000000") to represent a special
meaning. The problem is that I don't know if there is a chance that
a
command like "Guid.NewGuid()"would generate a Guid.Empty value could
this be possible or is the "00000000-0000-0000-0000-000000000000"
Guid
reserved or something like that?


Why not use a custom GUID for your special meaning?
The chances of a collision with some other GUID are
very very small. Remember, that low probability is
the whole reason GUID are in common use.
 
Guid.Empty is special but only int he context of .NET.

Guid is a value type and as such can not be null. Therefore, whenever
you declare a variable of type Guid that variable is automatically
initialized to a zero value. Since Guid isn't nullable, you can't
check if it's null. Therefore, to check if a Guid has been
initialized to a real generated Guid value compare it to Guid.Empty.

So instead of

// generates error...
if (myGuid != null) {
}

you use

if (myGuid != Guid.Empty) {
}

So Guid.Empty does have special meaning equivalent to a null value for
a reference type. That should be reason enough not to use it in your
app for some other purpose (besides the reasons already
mentioned--collision with another developer making the same assumption
as you).

HTH,

Sam



Thanks Nick.



I understood what Larry was saying, I was more curious than anything else,
you see, as you know, the Guid has a specific property called Empty that
represents the 0000...., that's why I was thinking that maybe the 0000....
was reserved for that special purpose (kind of like null in databases to
represent nothing) and it was impossible to get it though Guid.NewGuid().



Plain curiosity.
B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
 
Back
Top