How to generate a new GUID?

前端 未结 6 1340
不知归路
不知归路 2020-11-29 02:15

I\'m working on a web service which requires a new GUID() passed as a reference to a method within the service.

I am not familiar with C#

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 02:42

    According to Is there any difference between a GUID and a UUID?

    GUID is Microsoft's implementation of the UUID standard.

    So, here's a link to libraries, that let's you create UUIDs of the following types:

    • version 1 (time-based)
    • version 3 (name-based and hashed with MD5)
    • version 4 (random)
    • version 5 (name-based and hashed with SHA1)

    https://github.com/search?p=1&q=uuid+php&ref=cmdform&type=Repositories

    I don't know exactly, which one C# is using, but that's at least something you can use if you're writing some piece of software and want to have universal unique identifiers.

    My perfered choice was https://github.com/fredriklindberg/class.uuid.php because it is just a simple PHP file and the most rated one (https://github.com/ramsey/uuid) had to much dependencies on other libraries, but his may change soon (see https://github.com/ramsey/uuid/issues/20).

    But if you really need a GUID (according to the Microsoft standard), they have a different generation process than these 4122. Wikipedia claims that

    GUIDs and RFC 4122 UUIDs should be identical when displayed textually

    http://en.wikipedia.org/wiki/Globally_Unique_Identifier#Binary_encoding

    In most cases, you should be fine by going for one of the PHP libs for UUIDs. I don't think you're meddling with Microsoft Component Object Model (COM), don't you?

提交回复
热议问题