# RFC: Move to RNG functions into ext/random

- Status: Declined
- Authors: Go Kudo zeriyoshi@gmail.com
- Date: 2021-09-07
- Version: 1.1
- Original: https://wiki.php.net/rfc/random_ext
- Page: https://externals.io/rfc/random_ext
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Discussions on the mailing list

- [\[RFC\] Random Extension 3.0](https://externals.io/message/115918.md) — started on 2021-09-02, 29 messages
- [\[RFC\] Move RNG functions ext/random](https://externals.io/message/115975.md) — started on 2021-09-06, 2 messages

---

## Note

This RFC has been moved to Decline, as it is no longer needed due to changes in the proposal.

## Introduction

This is due to the historical background, starting with lcg.c / php\_lcg.h, the first implementation of the linear congruential generator (LCG), followed by rand.c / php\_rand.c, which calls the libc random number implementation, and the Mersenne Twister implementation. mt\_rand.c / php\_mt\_rand.h, an implementation of the Mersenne Twister, and random.c / php\_random.h, a CSPRNG implementation, respectively, in the ext/standard extension.

The rand.c / php\_rand.h to call the libc implementation is no longer relevant due to its alias to the Mersenne Twister in PHP 7.1, and is left for compatibility only.

RNGs are a frequently used feature in various implementations, and it is suggested that RNG-related functionality be carved out of the ext/standard extension and kindly made into an ext/random extension to reduce complexity and allow for future extensibility.

## Proposal

Create a new ext/random extension and move all the following functions of the ext/standard extension.

Userland Functions:

- lcg\_value()
- srand()
- rand()
- mt\_srand()
- mt\_rand()
- random\_int()
- random\_bytes()

Internal APIs:

- php\_random\_int\_throw()
- php\_random\_int\_silent()
- php\_combined\_lcg()
- php\_srand()
- php\_rand()
- php\_mt\_srand()
- php\_mt\_rand()
- php\_mt\_rand\_range()
- php\_mt\_rand\_common()
- php\_random\_bytes()
- php\_random\_int()

These features are provided in a single random.c / php\_random.h, and ext/random is always bundled with all builds of PHP, as is ext/standard.

In addition, header files containing the following contents will continue to be provided for extensions and downstream projects that previously depended on ext/standard features. These are a transitional measure until the next major version and will be removed in the future.

- standard/php\_lcg.h
- standard/php\_rand.h
- standard/php\_mt\_rand.h
- standard/php\_random.h

## Backward Incompatible Changes

none

## Proposed PHP Version(s)

PHP 8.2

## RFC Impact

### To SAPIs

none

### To Existing Extensions

Will need to change the including header file.

### To Opcache

none

### New Constants

none

### php.ini Defaults

none

## Open Issues

none

## Patches and Tests

<https://github.com/php/php-src/pull/7473>

## Implementation

<https://github.com/php/php-src/pull/7473>

## References

<https://externals.io/message/115918>[https://wiki.php.net/rfc/rng\_extension](https://externals.io/rfc/rng_extension)
