note 64495 added to function.uniqid
| From: | maciej dot strzelecki at gmail dot com | Date: | Sun, 16 Apr 2006 18:09:27 +0000 |
| Subject: | note 64495 added to function.uniqid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108277@lists.php.net to get a copy of this message | ||
This is an implementation of version 4 UUID, which is generating UUIDs from truly-random numbers.
<?php
/* Copyright 2006 Maciej Strzelecki
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
function uuid()
{
// version 4 UUID
return sprintf(
'%08x-%04x-%04x-%02x%02x-%012x',
mt_rand(),
mt_rand(0, 65535),
bindec(substr_replace(
sprintf('%016b', mt_rand(0, 65535)), '0100', 11, 4)
),
bindec(substr_replace(sprintf('%08b', mt_rand(0, 255)), '01', 5, 2)),
mt_rand(0, 255),
mt_rand()
);
}
?>
----
Server IP: 195.136.184.34
Probable Submitter: 213.238.125.33
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.uniqid.php
Edit -- http://master.php.net/note/edit/64495
Del: integrated -- http://master.php.net/note/delete/64495/integrated
Del: useless -- http://master.php.net/note/delete/64495/useless
Del: bad code -- http://master.php.net/note/delete/64495/bad+code
Del: spam -- http://master.php.net/note/delete/64495/spam
Del: non-english -- http://master.php.net/note/delete/64495/non-english
Del: in docs -- http://master.php.net/note/delete/64495/in+docs
Del: other reasons-- http://master.php.net/note/delete/64495
Reject -- http://master.php.net/note/reject/64495
Search -- http://master.php.net/manage/user-notes.php