← All built-ins / random_bytes()
random_bytes()
random_bytes(int $n): string
Parameters
| Name | Type | Description |
|---|---|---|
| $n | int | byte count (1–1024) |
Return value
$n cryptographically secure random bytes as a binary string.
Example
$tok = bin2hex(random_bytes(16)); echo strlen($tok) == 32 ? "token-ok" : "token-bad";
token-ok