UUID(全球唯一码生成)-----待测试

整理网上UUID的使用方法:

1.Linux:使用uuid_generate函数(UUID)

//编译命令:gcc atemp.c -o atemp -luuid

#include   
  
int main()  
{  
    uuid_t uu;  
    int i;  
    uuid_generate( uu );  
  
    for(i=0;i<16;i++)  
    {  
        printf("%02X-",uu[i]);  
    }  
    printf("\n");  
    return 0;  
}

2.在Qt中生成UUID(全球唯一码)

#include 
 
   QUuid id = QUuid::createUuid();
   QString strId = id.toString();

3.Windows:使用CoCreateGuid函数(GUID)

#include   
#define GUID_LEN 64  
    
int main(int argc, char* argv[])  
{  
    char buffer[GUID_LEN] = { 0 };  
    GUID guid;  
    
    if (CoCreateGuid(&guid))  
    {  
        fprintf(stderr, "create guid error\n");  
        return -1;  
    }  
    _snprintf(buffer, sizeof(buffer),  
        "%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X",  
        guid.Data1, guid.Data2, guid.Data3,  
        guid.Data4[0], guid.Data4[1], guid.Data4[2],  
        guid.Data4[3], guid.Data4[4], guid.Data4[5],  
        guid.Data4[6], guid.Data4[7]);  
    printf("guid: %s\n", buffer);  
    return 0;  
}

4.C#

using System;
 
namespace Demo{
     
public class Test{
         
public static void Main()
{
            Guid guid=Guid.NewGuid();
            Console.WriteLine(guid);
        }
    }
}

5.JAVA

package com.mytest;
 
import java.util.UUID; 
 
public class UTest {
     
public static void main(String[] args) {
         
UUID uuid = UUID.randomUUID();
         
System.out.println(uuid);
     
    }
}

6.GO

package main
import(
 
"github.com/nu7hatch/gouuid"
     
"fmt"
 
)
 
func main(){
     
fmt.Println(uuid.NewV4())
 
}

7.PYTHON

#coding=utf-8
 
import uuid
 
name = 'test_name'
namespace = 'test_namespace'
 
print uuid.uuid1()
print uuid.uuid3(namespace,name)
print uuid.uuid4()
print uuid.uuid5(namespace,name)

 

你可能感兴趣的:(Linux)