Re: [RFC] [Under Discussion] Random Extension Improvement

From: Date: Mon, 20 Jun 2022 17:00:02 +0000
Subject: Re: [RFC] [Under Discussion] Random Extension Improvement
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-118023@lists.php.net to get a copy of this message
Hi On 6/20/22 07:20, Go Kudo wrote:
What about a signature like `Randomizer::pickArrayKeys(array $array, int $num): array`? The previous behavior when int $num is 1 can be easily reproduced as follows:
$randomizer = new Random\Randomizer(new Random\Engine\Mt19937(1234,
MT_RAND_PHP));
[$key] = $randomizer->pickArrayKeys(['foo', 'bar', 'baz'], 1);
I like that one.
If multiple keys are returned, they will be returned in the order they
were present in the original array. Perhaps there is no particular significance to this specification. I don't think it is necessary, but considering the drop-in replacement from array_rand(), I think it is desirable to leave it as is.
I agree. Best regards Tim Düsterhus

« previous php.internals (#118023) next »