zoukankan      html  css  js  c++  java
  • GUID,UUID

    <?
    class  System
    {
                    function  currentTimeMillis()
                    {
                                    list($usec,  $sec)  =  explode("  ",microtime());
                                    return  $sec.substr($usec,  2,  3);
                    }
    }
    class  NetAddress
    {
                    var  $Name  =  'localhost';
                    var  $IP  =  '127.0.0.1';
                    function  getLocalHost()  //  static
                    {
                                    $address  =  new  NetAddress();
                                    $address->Name  =  $_ENV["COMPUTERNAME"];
                                    $address->IP  =  $_SERVER["SERVER_ADDR"];
                                    return  $address;
                    }
                    function  toString()
                    {
                                    return  strtolower($this->Name.'/'.$this->IP);
                    }
    }
    class  Random
    {
                    function  nextLong()
                    {
                                    $tmp  =  rand(0,1)?'-':'';
                                    return  $tmp.rand(1000,  9999).rand(1000,  9999).rand(1000,  9999).rand(100,  999).rand(100,  999);
                    }
    }
    //  三段
    //  一段是微秒  一段是地址  一段是随机数
    class  Guid
    {
                    var  $valueBeforeMD5;
                    var  $valueAfterMD5;
                    function  Guid()
                    {
                                    $this->getGuid();
                    }
    //
                    function  getGuid()
                    {
                                    $address  =  NetAddress::getLocalHost();
                                    $this->valueBeforeMD5  =  $address->toString().':'.System::currentTimeMillis().':'.Random::nextLong();
                                    $this->valueAfterMD5  =  md5($this->valueBeforeMD5);
                    }
                    function  newGuid()
                    {
                                    $Guid  =  new  Guid();
                                    return  $Guid;
                    }
                    function  toString()
                    {
                                    $raw  =  strtoupper($this->valueAfterMD5);
                                    return  substr($raw,0,8).'-'.substr($raw,8,4).'-'.substr($raw,12,4).'-'.substr($raw,16,4).'-'.substr($raw,20);
                    }
    }
    ?>

    引用:

    include"上面文件";
    $Guid = new Guid();
    $id = $Guid->toString();
  • 相关阅读:
    bzoj1001 狼抓兔子
    bzoj1015 星球大战
    noip模拟赛 楼
    noip模拟赛 radius
    noip模拟赛 helloworld
    noip模拟赛 hungary
    noip模拟赛 gcd
    洛谷P3375【模板】KMP字符串匹配
    noip模拟赛 隔壁
    noip模拟赛 对刚
  • 原文地址:https://www.cnblogs.com/h-g-f-s123/p/5763281.html
Copyright © 2011-2022 走看看