3 * The Rand Random Number Source
5 * This source generates low strength random numbers by using the internal
6 * rand() function. By itself it is quite weak. However when combined with
7 * other sources it does provide significant benefit.
11 * @category PHPCryptLib
14 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
15 * @copyright 2011 The Authors
16 * @license http://www.opensource.org/licenses/mit-license.html MIT License
17 * @version Build @@version@@
20 namespace CryptLib\Random\Source
;
22 use CryptLib\Core\Strength
;
25 * The Rand Random Number Source
27 * This source generates low strength random numbers by using the internal
28 * rand() function. By itself it is quite weak. However when combined with
29 * other sources it does provide significant benefit.
31 * @category PHPCryptLib
34 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
37 class Rand
implements \CryptLib\Random\Source
{
40 * Return an instance of Strength indicating the strength of the source
42 * @return Strength An instance of one of the strength classes
44 public static function getStrength() {
45 // Detect if Suhosin Hardened PHP patch is applied
46 if (defined('S_ALL')) {
47 return new Strength(Strength
::LOW
);
49 return new Strength(Strength
::VERYLOW
);
54 * Generate a random string of the specified size
56 * @param int $size The size of the requested random string
58 * @return string A string of the requested size
60 public function generate($size) {
62 for ($i = 0; $i < $size; $i++
) {
63 $result .= chr((rand() ^
rand()) %
256);