Re: Re: rand_str
| From: | Jeroen van Wolffelaar | Date: | Sun, 05 Aug 2001 19:17:34 +0000 |
| Subject: | Re: Re: rand_str | ||
| References: | 1 2 3 4 5 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-62167@lists.php.net to get a copy of this message | ||
> >> and it is extremely easy to implement in
> >> userland:
> >
> >That is not true,
>
> So how about this?
>
> function str_rand($len=8)
> {
> $retval = strtr(md5(microtime()), chr(0x30), chr(0x4F));
> return substr($retval,0,$len);
> }
>
> for($i=0; $i<10; $i++){
> echo str_rand(), "\n";
> }
I find rand_str($len , "1..9a..f\x4F") easier... ;-)
And this is still yielding exactly 16 differerent characters.
As you saw for yourself, it is not trivial to implement something like this
in userland. For example str_pad is way easier to implement, only some
playing with str_repeat.
Are there any objections if I implement this? Are you still against this new
function?
Jeroen