php中生成uuid的方法

Generate name based md5 UUID (version 3)

/**
* Generate name based md5 UUID (version 3).
* @example '7e57d004-2b97-0e7a-b45f-5387367791cd'
*/
public function uuid()
{
// fix for compatibility with 32bit architecture; seed range restricted to 62bit
$seed = mt_rand(0, 2147483647) . '#' . mt_rand(0, 2147483647); // Hash the seed and convert to a byte array
$val = md5($seed, true);
$byte = array_values(unpack('C16', $val)); // extract fields from byte array
$tLo = ($byte[0] << 24) | ($byte[1] << 16) | ($byte[2] << 8) | $byte[3];
$tMi = ($byte[4] << 8) | $byte[5];
$tHi = ($byte[6] << 8) | $byte[7];
$csLo = $byte[9];
$csHi = $byte[8] & 0x3f | (1 << 7); // correct byte order for big edian architecture
if (pack('L', 0x6162797A) == pack('N', 0x6162797A)) {
$tLo = (($tLo & 0x000000ff) << 24) | (($tLo & 0x0000ff00) << 8)
| (($tLo & 0x00ff0000) >> 8) | (($tLo & 0xff000000) >> 24);
$tMi = (($tMi & 0x00ff) << 8) | (($tMi & 0xff00) >> 8);
$tHi = (($tHi & 0x00ff) << 8) | (($tHi & 0xff00) >> 8);
} // apply version number
$tHi &= 0x0fff;
$tHi |= (3 << 12); // cast to string
$uuid = sprintf(
'%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x',
$tLo,
$tMi,
$tHi,
$csHi,
$csLo,
$byte[10],
$byte[11],
$byte[12],
$byte[13],
$byte[14],
$byte[15]
); return $uuid;
}

函数来源:fzaninotto/faker

地址:https://github.com/fzaninotto/Faker

PHP 生成 UUID 函数的更多相关文章

  1. mysql 生成UUID() 即 ORACLE 中的guid()函数

    MYSQL 生成UUID 即 guid 函数-- 带 - 的UUIDselect UUID() -- 去掉 - 的UUIDselect replace(uuid(),'-','') 一个表的数据插入另 ...

  2. php生成UUID

    UUID含义是 通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Open Software Foundation, O ...

  3. java生成UUID通用唯一识别码 (Universally Unique Identifier)

    转自:http://blog.csdn.net/carefree31441/article/details/3998553 UUID含义是通用唯一识别码 (Universally Unique Ide ...

  4. (转)java生成UUID通用唯一识别码 (Universally Unique Identifier)

    (原文链接:http://blog.csdn.net/carefree31441/article/details/3998553)   UUID含义是通用唯一识别码 (Universally Uniq ...

  5. PostgreSQL 下生成 UUID(Guid)

    最近在Windows 10 下安装了 PostgreSQL(postgresql-9.6.3-1-windows.exe),在学习过程中,发现PostgreSQL 支持UUID(Guid)类型,但是却 ...

  6. [转载]MySQL UUID() 函数

    目录 目录 一 引子 二 MySQL UUID() 函数 三 复制中的 UUID()四 UUID_SHORT() 函数 3.1 实验环境介绍 3.2 搭建复制环境 3.3 基于 STATEMENT 模 ...

  7. Windows 10 下 PostgreSQL 生成 UUID(Guid)

    最近在Windows 10 下安装了 PostgreSQL(postgresql-9.6.3-1-windows.exe),在学习过程中,发现PostgreSQL 支持UUID(Guid)类型,但是却 ...

  8. Oracle中生成uuid的方法

    Oracle中生成uuid的方法 下载LOFTER客户端 在Oracle SQL 提供了一个生成uuid的函数sys_guid: http://download.oracle.com/docs/cd/ ...

  9. MySQL UUID函数的详解(转)

    MySQL UUID函数的详解 MySQL中可以有二类用于生成唯一值性质的工具:UUID()函数和自增序列,那么二者有何区别呢?我们就此对比下各自的特性及异同点: l  都可以实现生成唯一值的功能: ...

随机推荐

  1. POJ2528---Mayor's posters

    The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...

  2. Ceph 介绍及原理架构

  3. ARTS-S mongo关闭与启动

    关闭 mongo admin --eval "db.shutdownServer()" 删除dbdata目录下的mongo.lock 启动 /usr/bin/mongod --db ...

  4. 初次接触tensorflow

    要确保已经明白神经网络和卷积神经网络的原理.如果不明白,先学习参考资料1.tensorflow中有很多api,可以分成2大类.1类是比较低层的api(tf.train),叫TensorFlow Cor ...

  5. ef not in

    //not in linq var xx=(from c in measStateDetail where !((from d in breakInstr select d.InstrCode).Co ...

  6. 各种常用js函数实现

    1.bind function bind(fn, context) {    var args = Array.prototype.slice.call(arguments, 2);    retur ...

  7. Pycharm-2018.3.1专业版破解教程

    1.去官网下载并安装2018.3.1(目前最新)专业版本的Pycharm:(https://www.jetbrains.com/pycharm/download/#section=windows). ...

  8. Django 06

    目录 注意 聚合查询 分组查询 F与Q查询 orm字段和参数 自定义字段类型 事务 ACID 三大范式 开启事务 注意 只要和数据库相关的功能, 基本在 django.db.models 里面 聚合查 ...

  9. 回归损失函数2 : HUber loss,Log Cosh Loss,以及 Quantile Loss

    均方误差(Mean Square Error,MSE)和平均绝对误差(Mean Absolute Error,MAE) 是回归中最常用的两个损失函数,但是其各有优缺点.为了避免MAE和MSE各自的优缺 ...

  10. [权限管理系统篇] (五)-Spring security(授权过程分析)

    欢迎关注公众号[Ccww笔记],原创技术文章第一时间推出 前言 权限管理系统的组件分析以及认证过程的往期文章: Spring security (一)架构框架-Component.Service.Fi ...