php_mt 0.1.0

Bit-for-bit compatible implementation of PHP 7.1+ MT19937 (mt_rand)
Documentation
  • Coverage
  • 85.71%
    6 out of 7 items documented5 out of 6 items with examples
  • Size
  • Source code size: 11.13 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • schworak/php_mt
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • schworak

php_mt

Bit-for-bit compatible implementation of PHP 7.1+ MT19937 (mt_rand) in Rust.

This crate reproduces the exact output of:

  • mt_srand(seed)
  • mt_rand()
  • mt_rand(min, max)

for PHP 7.1 and newer.

It is intended for deterministic cross-language compatibility and reproducible test vectors — not for cryptographic use.


Features

  • Exact Zend Engine MT19937 constants
  • 624-element state array
  • 31-bit output for mt_rand() (matches PHP)
  • Integer rejection sampling for mt_rand(min, max)
  • No floating point scaling
  • No external dependencies
  • Fully deterministic

Example

use php_mt::PhpMt;

let mut rng = PhpMt::new(1234);

assert_eq!(rng.mt_rand(), 411284887);
assert_eq!(rng.mt_rand_range(0, 100), 20);