(PHP 8 >= 8.2.0)

Random\Randomizer::getBytesGet random bytes


public Random\Randomizer::getBytes(int $length): string

Generates a string containing uniformly selected random bytes with the requested length.

As the returned bytes are selected completely randomly, the resulting string is likely to contain unprintable characters or invalid UTF-8 sequences. It may be necessary to encode it before transmission or display.

Liste de paramètres


The length of the random chaîne de caractères that should be returned in bytes; must be 1 or greater.

Valeurs de retour

A chaîne de caractères containing the requested number of random bytes.

Erreurs / Exceptions


Exemple #1 Random\Randomizer::getBytes() example

= new \Random\Randomizer();

bin2hex($r->getBytes(8)), "\n";

Résultat de l'exemple ci-dessus est similaire à :


Voir aussi

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top