php的生成办法:
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);
}}
?>
然后就可以这样调用:
1. toString();
5. ?>
linux下可以用uuidgen命令来生成UUID,也可以在c/c++程序里调用:
/* clear.c */
void uuid_clear(uuid_t uu);/* compare.c */
int uuid_compare(const uuid_t uu1, const uuid_t uu2);/* copy.c */
void uuid_copy(uuid_t dst, const uuid_t src);/* gen_uuid.c */
void uuid_generate(uuid_t out);
void uuid_generate_random(uuid_t out);
void uuid_generate_time(uuid_t out);/* isnull.c */
int uuid_is_null(const uuid_t uu);/* parse.c */
int uuid_parse(const char *in, uuid_t uu);/* unparse.c */
void uuid_unparse(const uuid_t uu, char *out);/* uuid_time.c */
time_t uuid_time(const uuid_t uu, struct timeval *ret_tv);
int uuid_type(const uuid_t uu);
int uuid_variant(const uuid_t uu);
在ubuntu下,需要确认已经安装对应的库:
sudo aptitude install libuuid1 uuid-dev
发表回复