lundi 18 mai 2020

Why does Guid.NewGuid always have a 4 in the exact same spot?

I created a console application which just generated random GUIDs, but it came to my attention that it keeps having a 4 at the same location... Why is that?

Here's my code:

Sub Main()

    Dim generatedGuids = New List(Of String)
    Dim duplicateGenerated As Boolean = False
    Dim index As ULong = 0

    While Not duplicateGenerated

        Dim generatedGuid As String = Guid.NewGuid.ToString
        generatedGuids.Add(generatedGuid)

        duplicateGenerated = generatedGuids.Count <> generatedGuids.Distinct.Count

        index += 1

        Console.WriteLine(index & " - " & generatedGuid)


    End While

    Console.WriteLine("FOUND A DUPLICATE")

End Sub

(It's in VB.Net because I just took some online courses, and was playing around with it.)

Here's a screenshot:

enter image description here

As you can see, each generated GUID has a 4 at the exact same spot... Does anyone have an idea why?




Aucun commentaire:

Enregistrer un commentaire