2022年6月18日(土) 2:37 Tim Düsterhus <t...@bastelstu.be>: > Hi > > On 6/17/22 19:28, Go Kudo wrote > >> I don't think that ->pickString() is a good name > > > > I see. But I think `randomString()` is ambiguous with `getBytes()`. > > > > `stringFromCharset(string $string, int $num): string` solves that, but I > > think it is possible > > that the meaning of "char" is not well known in the PHP world (although I > > think this name is most appropriate) > > ->stringFromAlphabet()? > > > How about adding an optional `?int $num` argument to > `shuffleString(string > > $string, ?int $num): string`? > > > > No, because it would be pretty unclear what that `$num` argument would > do there. It specifically would be different from the `$num` of > `pickArrayKey()`. pickArrayKey() returns every key only once. Generating > a string from a given charset may return the same character multiple > times. Don't overload a single method with too many purposes. > > Best regards > Tim Düsterhus >
I was fundamentally wrong, I understand now. As you said, there was no interoperability with `pickArrayKey()` in the first place... > stringFromAlphabet() Hmmm. I guess randomString would be better then. At the same time, it would be nice to have an array version of randomArray. However, I don't want to add more methods without any thought. I think operations that can be done on userland should be done on userland. That is why I did not implement the array_rand() function in the first place. I would like to hear other people's opinions in this area. Incidentally, our own PHP implementation of the library (Xorshift128+) has equivalents for arrayPickKey, stringPick, arrayPickValue, randomArray, randomString. And it is useful. Regards Go Kudo