You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Arr::randomElement() differs slightly from Laravel's Arr::random() in that it can be seeded, using a specified seeding mode. However, from PHP v8.2, the Random\Randomizer::pickArrayKeys is available, and should be used instead.
Yet, the seeding process must be slightly changed. In order to seed the Randomizer, a different Random\Engine. So, perhaps a different set of methods should be designed to replace the Arr::randomElement().
Possible solution
The following could perhaps be better suitable method(s):
useRandom\Engine;
// Single random value from array - replacement for Arr::randomElement()publicstatic randomValue(array $arr, Enging|null$random = null): mixed;
// Keys are not preserved - intended difference from Laravel's Arr::random()publicstaticrandomValues(array $arr, int $amount, Enging|null$random = null): array;
// Single random array keypublicstaticrandomKey(array $arr, Enging|null$random = null): string|int;
// Uses Random\Randomizer::pickArrayKeys()publicstaticrandomKeys(array $arr, int $amount, Enging|null$random = null): array
Now each type of randomizer has its own responsibilities and less changes of naming conflicts (e.g. shuffleBytes() vs. shuffleArray() have both been renamed to shuffle()).
#150, #151
Description
The
Arr::randomElement()
differs slightly from Laravel'sArr::random()
in that it can be seeded, using a specified seeding mode. However, from PHPv8.2
, theRandom\Randomizer::pickArrayKeys
is available, and should be used instead.Yet, the seeding process must be slightly changed. In order to seed the
Randomizer
, a differentRandom\Engine
. So, perhaps a different set of methods should be designed to replace theArr::randomElement()
.Possible solution
The following could perhaps be better suitable method(s):
See also
The text was updated successfully, but these errors were encountered: