How to generate a new GUID?

前端 未结 6 1354
不知归路
不知归路 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:51

    You can try the following:

    function GUID()
    {
        if (function_exists('com_create_guid') === true)
        {
            return trim(com_create_guid(), '{}');
        }
    
        return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
    }
    

    Source - com_create_guid

提交回复
热议问题