| Crates.io | php_mt_seed |
| lib.rs | php_mt_seed |
| version | 1.0.1 |
| created_at | 2025-09-08 01:30:28.522016+00 |
| updated_at | 2025-09-08 01:34:02.53669+00 |
| description | a GPU-accelerated reimplementation of openwall's php_mt_seed (PHP 7.1.0+ only) |
| homepage | |
| repository | https://github.com/Max1Truc/php_mt_seed_rs |
| max_upload_size | |
| id | 1828712 |
| size | 95,709 |
php_mt_seed_rsA GPU-accelerated reimplementation of openwall's php_mt_seed (PHP 7.1.0+ only).
It searches for MT19937 seeds that produce given PHP mt_rand() outputs using a WebGPU (wgpu) compute shader.
8 times faster than the previous state of the art ! The numbers might vary depending on your configuration, but the ratio should stay more or less the same in most cases.

License: MIT OR Apache-2.0
mt_rand() outputs and optional ranges per output.Build in release mode for best performance:
cargo build --release
Usage pattern:
php_mt_seed_rs VALUE_OR_MATCH_MIN [MATCH_MAX [RANGE_MIN RANGE_MAX]] ...
match_min, match_max, range_min, range_max).0..0x7fffffff when omitted.Examples:
$ cargo run --release -- 1178568022
Finished `release` profile [optimized] target(s) in 0.05s
Running `target/release/php_mt_seed 1178568022`
Running on Adapter: AdapterInfo {
name: "NVIDIA GeForce GTX 1660 Ti",
vendor: 4318,
device: 8593,
device_type: DiscreteGpu,
driver: "NVIDIA",
driver_info: "575.64.05",
backend: Vulkan,
}
seed = 0x0 = 0 (PHP 7.1.0+)
seed = 0xab2bbe62 = 2871770722 (PHP 7.1.0+)
seed = 0xec3f338f = 3963564943 (PHP 7.1.0+)
seed = 0x6784fafb = 1736768251 (PHP 7.1.0+)
progress: 256 / 256
$ cat > mt_rand.php <<EOF # let's check !
<?php
mt_srand(0);
echo mt_rand() . "\n";
EOF
$ php mt_rand.php # this outputs the correct number
1178568022
$ cargo r --release -- 0 0 0 0 0 0 0 0 1457 1457 1000 10000 5452 5452 1000 10000 4474 4474 1000 10000
Finished `release` profile [optimized] target(s) in 0.08s
Running `target/release/php_mt_seed 0 0 0 0 0 0 0 0 1457 1457 1000 10000 5452 5452 1000 10000 4474 4474 1000 10000`
Running on Adapter: AdapterInfo {
name: "NVIDIA GeForce GTX 1660 Ti",
vendor: 4318,
device: 8593,
device_type: DiscreteGpu,
driver: "NVIDIA",
driver_info: "575.64.05",
backend: Vulkan,
}
seed = 0x67932 = 424242 (PHP 7.1.0+)
progress: 256 / 256
$ cat > mt_rand.php <<EOF # let's check !
<?php
mt_srand(424242);
mt_rand();
mt_rand();
echo mt_rand(1000, 10000) . "\n";
echo mt_rand(1000, 10000) . "\n";
echo mt_rand(1000, 10000) . "\n";
EOF
$ php mt_rand.php # this outputs the correct numbers
1457
5452
4474
Unit/integration tests call the GPU prepare/execute code and therefore require a working GPU/wgpu environment. They may fail in environments without a compatible GPU or drivers.
To run tests:
cargo test
php_mt_seed tool for large result sets.Contributions and bug reports are welcome — open an issue or PR.