3 * The UniqID Random Number Source
5 * This uses the internal `uniqid()` function to generate low strength random
10 * @category PHPCryptLib
13 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
14 * @copyright 2011 The Authors
15 * @license http://www.opensource.org/licenses/mit-license.html MIT License
16 * @version Build @@version@@
19 namespace CryptLib\Random\Source
;
21 use CryptLib\Core\Strength
;
24 * The UniqID Random Number Source
26 * This uses the internal `uniqid()` function to generate low strength random
29 * @category PHPCryptLib
32 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
35 class UniqID
implements \CryptLib\Random\Source
{
38 * Return an instance of Strength indicating the strength of the source
40 * @return Strength An instance of one of the strength classes
42 public static function getStrength() {
43 return new Strength(Strength
::LOW
);
47 * Generate a random string of the specified size
49 * @param int $size The size of the requested random string
51 * @return string A string of the requested size
53 public function generate($size) {
55 while (strlen($result) < $size) {
56 $result = uniqid($result, true);
58 return substr($result, 0, $size);