For testing and learning purpose, I wanted to modify the php rand and mt_rand functions which are in https://github.com/php/php-src:ext/standard/rand.c.
I wanted to give a fixed output each time rand function is called and for this purpose I modified the code
PHPAPI long php_rand(TSRMLS_D)
{
long ret;
if (!BG(rand_is_seeded)) {
php_srand(GENERATE_SEED() TSRMLS_CC);
}
#ifdef ZTS
ret = php_rand_r(&BG(rand_seed));
#else
# if defined(HAVE_RANDOM)
ret = random();
# elif defined(HAVE_LRAND48)
ret = lrand48();
# else
ret = rand();
# endif
#endif
// ignoring the results coming from the calls above and
// returning a constant value
ret = 3264;
return ret;
}
compiled
./configure
make
make install
and finally called the rand function as echo rand(3000,4000); and it always returns 3000.
What would be the way to modify this function? and why there is TSRMLS_D but not the range parameters?