At 21:53 8/5/2001, Jeroen van Wolffelaar wrote the following:
-------------------------------------------------------------- 
>> Hi Jeroen,
>>
>> I think we're not on the same page. :) I consider both versions
>> of str_rand() I posted trivial...
>
>Agree. But they are not what rand_str could do. The result has
>16 different chars, just because md5 happens to have that much.
>
>Implementing something that has NOT that limitation, is far less trivial.

function str_rand($len = 8, $class = 'a-zA-Z1-9')
{
    static $init = 1;
    if(1 == $init){
        mt_srand((double) microtime() * 1000000);
        $init = 0;
    }
    $chars = array();
    for($i = 0; $i < $len; $i++){
        $chars[] = chr(mt_rand(0,255));
    }
    return implode('', preg_grep('|['.preg_quote($class).']|',$chars));
}

Just a little bit different syntax for the second argument.
What's the big deal? :)

>> Also, and this is strictly subjective, I don't think the function
>> needs to be implemented natively. As I said, it's trivial. :) But
>> my stance could be rated as -0.3... Actually, as I'm thinking about
>> it, -0.2.
>
>k, mine is 0.8, 0.9, on the idea, not the details
>
>> as for the rand_str($len , "1..9a..f\x4F") proto:
>> I don't like it. KISS.
>
>Better suggestions? Simple length and a list of characters... and the
>list-of-characters way is also in addcslashes, and the trims.
>
>Jeroen
------end of quote------ 


[EMAIL PROTECTED]
-------------
And the eyes of them both were opened and they saw that their files
were world readable and writable, so they chmoded 600 their files.
    - Book of Installation chapt 3 sec 7 


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to