Dutch PHP Conference 2025 - Call For Papers

Random\Engine\Secure::generate

(PHP 8 >= 8.2.0)

Random\Engine\Secure::generateGenerate cryptographically secure randomness

Опис

public Random\Engine\Secure::generate(): string

Returns cryptographically secure randomness.

Генератори випадковостей, впорядковані за пріоритетом:

  • Linux: » getrandom(), /dev/urandom

  • FreeBSD >= 12 (PHP >= 7.3): » getrandom(), /dev/urandom

  • Windows (PHP >= 7.2): » CNG-API

    Windows: » CryptGenRandom

  • macOS (PHP >= 8.2; >= 8.1.9; >= 8.0.22, якщо CCRandomGenerateBytes доступний під час компіляції): CCRandomGenerateBytes()

    macOS (PHP >= 8.1; >= 8.0.2): arc4random_buf(), /dev/urandom

  • NetBSD >= 7 (PHP >= 7.1; >= 7.0.1): arc4random_buf(), /dev/urandom

  • OpenBSD >= 5.5 (PHP >= 7.1; >= 7.0.1): arc4random_buf(), /dev/urandom

  • DragonflyBSD (PHP >= 8.1): » getrandom(), /dev/urandom

  • Solaris (PHP >= 8.1): » getrandom(), /dev/urandom

  • Для будь-якої іншої комбінації операційної системи та версії PHP: /dev/urandom
  • Якщо жоден генератор випадковостей не доступний або не працює, то буде викинуто Random\RandomException.

Параметри

У цієї функції немає параметрів.

Значення, що повертаються

A string containing PHP_INT_SIZE cryptographically secure random bytes.

Помилки/виключення

  • Якщо жоден генератор випадковостей не доступний, то буде викинуто Random\RandomException.
add a note

User Contributed Notes

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