Overview
KB
Technical FAQ
PHP Manual
CSS2 Manual
HTML Manual
JS Guide
JS Reference
PhpDock Manual
Nu-Coder Manual
PhpExpress Manual
PHP Joomla
Development
Learn PHP
 
<Random\IntervalBoundaryRandom\Engine::generate>
^RandomLast updated: Mon, 26 Oct 2026

The Random\Engine interface

(PHP 8 >= 8.2.0)

Introduction

A Random\Engine provides a low-level source of randomness by returning random bytes that are consumed by high-level APIs to perform their operations. The Random\Engine interface allows swapping out the algorithm used to generate randomness, because each algorithm makes different tradeoffs to fit specific use-cases. Some algorithms are very fast, but generate lower-quality randomness, whereas other algorithms are slower, but generate better randomness, up to cryptographically secure randomness as provided by the Random\Engine\Secure engine.

PHP provides several Random\Engines out of the box to accommodate different use-cases. The Random\Engine\Secure engine that is backed by a CSPRNG is the recommended safe default choice, unless the application requires either reproducible sequences or very high performance.

Interface synopsis

namespace Random;
interface Engine {
/* Methods */
public function generate(): string
}

Table of Contents


<Random\IntervalBoundaryRandom\Engine::generate>
^RandomLast updated: Mon, 26 Oct 2026