JBZoo\Utils\Str::uuid PHP Method

uuid() public static method

Returns Version 4 UUID format: xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx where x is any random hex digit and Y is a random choice from 8, 9, a, or b.
See also: http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid
public static uuid ( ) : string
return string
    public static function uuid()
    {
        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
    }

Usage Example

Example #1
0
 public function testGenerateUUID()
 {
     isNotSame(Str::uuid(), Str::uuid());
     isNotSame(Str::uuid(), Str::uuid());
     isNotSame(Str::uuid(), Str::uuid());
 }