W3cubDocs

/PHP

The Random\Engine\Secure class

Introduction

(PHP 8 >= 8.2.0)

Generates cryptographically secure randomness using the operating system’s CSPRNG.

The randomness generated by this Random\Engine is suitable for all applications, including the generation of long-term secrets, such as encryption keys.

The Random\Engine\Secure engine is the recommended safe default choice, unless the application requires either reproducible sequences or very high performance.

Class synopsis

final class Random\Engine\Secure implements Random\CryptoSafeEngine {
/* Methods */
public generate(): string
}

Table of Contents

© 1997–2025 The PHP Documentation Group
Licensed under the Creative Commons Attribution License v3.0 or later.
https://www.php.net/manual/en/class.random-engine-secure.php