0

If I create two GUIDs then I understand they will be unique but is part of that dependent on the time. I would like to create a random string that is completely random.

Maybe if someone knows how a GUID is created that would help me to understand.

Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427
  • http://en.wikipedia.org/wiki/Globally_unique_identifier#Algorithm – Frédéric Hamidi Jun 26 '14 at 07:42
  • There is a somewhat related question here: http://stackoverflow.com/questions/1752004/sequential-guid-generator-c-sharp – David Brabant Jun 26 '14 at 07:43
  • the c# implementation calls CoCreateGuid, which calls UuidCreate http://msdn.microsoft.com/en-US/library/windows/desktop/aa379205.aspx "The UuidCreate function generates a UUID that cannot be traced to the ethernet address of the computer on which it was generated. It also cannot be associated with other UUIDs created on the same computer. " – Jay Jun 26 '14 at 07:48
  • 2
    Unless you have access to specialized hardware, there is no way for a computer to create a random value that is *truly* random. It will always follow some kind of pattern. Also, no, you should not rely on any part of the guid as a timestamp. If you need a timestamp, implement a timestamp. A guid is a different type of value, meant for uniqueness. – Lasse V. Karlsen Jun 26 '14 at 07:49
  • possible duplicate of [Is a GUID unique 100% of the time?](http://stackoverflow.com/questions/39771/is-a-guid-unique-100-of-the-time) – Tolga Evcimen Jun 26 '14 at 07:49

2 Answers2

2

If I create GUIDs then is there a way I can check if one GUID is created after another?

No. There are lots of ways to make GUIDs. Nothing in the GUID encodes the time. It is possible that a poorly implemented GUID generator would encode the time of generation, but in general, given a GUID, you do not know the algorithm used to generate it.

I would like to create a random string that is completely random.

Use a good quality random number generator. Although be warned that its hard to find true random number generators on a general computer. Usually the best you can do is use a pseudo random number generator.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • @RussellHorwood *Simply don't exist*. Depends on your definitions I suppose. I'm thinking of the sort of RNGs described here: http://en.wikipedia.org/wiki/Random_number_generation#.22True.22_random_numbers_vs._pseudo-random_numbers – David Heffernan Jun 26 '14 at 08:25
  • @RussellHorwood A deterministic computation yields a PRNG. But true RNGs do exist. They just aren't quite as practical on a general purpose computer. That's all I meant. I suppose I was trying to point out to the asker that a desire for "completely random" will not be met perfectly by a PRNG. – David Heffernan Jun 26 '14 at 09:03
  • None of this is important. – Russell Horwood Jun 26 '14 at 09:06
0

-- Wikipedia's answers this clearly --

GUIDs are usually stored as 128-bit values, and are commonly displayed as 32 hexadecimal digits with groups separated by hyphens, such as {21EC2020-3AEA-4069-A2DD-08002B30309D}. GUIDs generated from random numbers sometimes contain 6 fixed bits saying they are random and 122 random bits; the total number of unique such GUIDs is 2122 (approximately 5.3×1036). This number is so large that the probability of the same number being generated randomly twice is negligible; however other GUID versions have different uniqueness properties and probabilities, ranging from guaranteed uniqueness to likely non-uniqueness. Assuming uniform probability for simplicity, the probability of one duplicate would be about 50% if every person on earth as of 2014 owned 600 million GUIDs.

Here is the source for C# if you want a more intrinsic understanding: http://referencesource.microsoft.com/#mscorlib/system/guid.cs

Dane Balia
  • 5,271
  • 5
  • 32
  • 57