PHP 8.3.0 RC 6 available for testing

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.

错误/异常

add a note

User Contributed Notes

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