# [RFC] Object-scope RNG again

- Thread: https://externals.io/message/113720
- Original archive: https://news-web.php.net/php.internals/113720
- Started by Go Kudo on 2021-03-23T14:44:25+00:00
- Messages: 1
- RFC: Object scoped RNG Implementations (Declined) — https://externals.io/rfc/object_scope_prng.md
- Reply by email to internals@lists.php.net
- 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

---

## #113720 — Go Kudo — 2021-03-23T14:44:25+00:00

URL: https://externals.io/message/113720#113720

Hi internals.

The Fiber vote appears to have passed. Congratulations!

Now, while Fiber is a very nice feature, it has increased the severity of
MT's global state problems.

I have prepared an example using amphp. It is difficult to predict the
results of the following run, and there appears to be no guarantee that
consistency will be maintained.

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use function Amp\defer;
use function Amp\delay;

function task(int $i): void {
    global $running;

    while ($running) {
        delay(250);
        echo "${i} : " . `mt_rand()` . "\n";
    }
}

mt_srand(1234);

$running = true;

defer(fn() => task(1));
defer(fn() => task(2));
defer(fn() => task(3));
defer(fn() => task(4));

delay(1000);
$running = false;

/*
Result:
1 : 411284887
4 : 1068724585
2 : 1335968403
3 : 1756294682
1 : 940013158
3 : 1314500282
4 : 1686544716
2 : 1656482812
1 : 1674985287
2 : 1848274264
3 : 585388171
4 : 323490420
4 : 593702477
3 : 426315791
2 : 1722007381
1 : 1750549071
*/
```

I have added a note to the RFC wiki about this issue. Also, the namespace
voting option has been removed, as Nikita has already provided a suitable
RFC.

https://wiki.php.net/rfc/object_scope_prng

Perhaps now is the time to discuss this proposal.

I would like to include this implementation in PHP 8.1's Fiber. If there is
no further discussion, I will move on to the voting phase.

Regards,
Go Kudo
