Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sinnbeck's avatar
Level 102

Retain seed from php 5.6 to 7.4

I have been tasked with upgrading and older system from php 5.6 to 7.4. It uses random with seeding to generate random (but the same each time) colors.

The issue I am facing is that the seeder + randomizer has been rewritten in 7.1, meaning that all colors are getting changed. Does anyone have experience with this? I was hoping to perhaps find a package that provided the 5.6 version of the randomizer (no such luck so far), or a way to get php 7.4 to use the older version, by using a flag

0 likes
1 reply
Sinnbeck's avatar
Level 102

According to the docs it should be possible to use MT_RAND_PHP to get backwards compatibility..

https://www.php.net/manual/en/function.mt-srand.php

But that does not seem to work

Php 7.4

<?php
 srand(2, MT_RAND_PHP);
 echo rand(0,200); //113

Php 5.6

<?php
 srand(2);
 echo rand(0,200); //140

But I think this is assuming the usage of the mt_ functions (which the legacy code sadly isnt)

Please or to participate in this conversation.