Skip to content

Commit

Permalink
Merge pull request #4 from open-source-contributions/improve_array_rand
Browse files Browse the repository at this point in the history
Using the random_int to improve array_rand
  • Loading branch information
pH-7 authored Nov 30, 2022
2 parents 091a3b9 + 2749589 commit 5106fe4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Generator/Password.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public static function generate(int $length = self::DEFAULT_LENGTH, bool $specia
range('Z', 'Z'),
$specialCharacters ? self::SPECIAL_CHARACTERS : []
);
$endKeysIndex = count($keys) - 1;

for ($amount = 0; $amount < $length; $amount++) {
$password .= $keys[array_rand($keys)];
$password .= $keys[random_int(0, $endKeysIndex)];
}

return $password;
Expand Down

0 comments on commit 5106fe4

Please sign in to comment.