PHP 8.4.0 RC4 available for testing

Random\Randomizer::getBytes

(PHP 8 >= 8.2.0)

Random\Randomizer::getBytesGet random bytes

Beschreibung

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.

Parameter-Liste

length

The length of the random String that should be returned in bytes; must be 1 or greater.

Rückgabewerte

A String containing the requested number of random bytes.

Fehler/Exceptions

Beispiele

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

<?php
$r
= new \Random\Randomizer();

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

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

ebdbe93cd56682c2

Siehe auch

add a note

User Contributed Notes

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