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.

5
  • en.wikipedia.org/wiki/Globally_unique_identifier#Algorithm Commented Jun 26, 2014 at 7:42
  • There is a somewhat related question here: stackoverflow.com/questions/1752004/… Commented Jun 26, 2014 at 7:43
  • the c# implementation calls CoCreateGuid, which calls UuidCreate 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. " Commented Jun 26, 2014 at 7: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. Commented Jun 26, 2014 at 7:49
  • possible duplicate of Is a GUID unique 100% of the time? Commented Jun 26, 2014 at 7:49

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@RussellHorwood Simply don't exist. Depends on your definitions I suppose. I'm thinking of the sort of RNGs described here: en.wikipedia.org/wiki/…
@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.
None of this is important.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.