/**
* Class for generating a random ID string. This string uses all characters
- * in the class [0-9a-z].
+ * in the class [0-9a-zA-Z].
*
* <code>
* <?php
*
- * $rid = (string)new Horde_Support_Randomid([$length = 16]);
+ * $rid = (string)new Horde_Support_Randomid();
*
* ?>
* </code>
/**
* New random ID.
- *
- * @param integer $length The length of the ID.
*/
- public function __construct($length = 16)
+ public function __construct()
{
- $this->generate($length);
+ $this->generate();
}
/**
* Generate a random ID.
- *
- * @param integer $length The length of the ID.
*/
- public function generate($length = 16)
+ public function generate()
{
- $this->_rid = substr(base_convert(dechex(strtr(microtime(), array('0.' => '', ' ' => ''))) . strtr(uniqid(mt_rand(), true), array('.' => '')), 16, 36), 0, $length);
+ $this->_rid = rtrim(base64_encode(pack('H*', strtr(uniqid(mt_rand(), true), array('.' => '')) . dechex(getmypid()))), '=');
}
/**
*/
class Horde_Support_RandomidTest extends PHPUnit_Framework_TestCase
{
- public function testRandomidLength()
- {
- $rid = (string)new Horde_Support_Randomid;
- $this->assertEquals(16, strlen($rid));
- }
-
public function testRandomidDuplicates()
{
$values = array();