I’ve been trying to wrap my head around solving this issue but I can’t seem to find a simple solution to it.
I have a dynamic grid layout, articles are placed on the grid but have different width & height. This width & height of these different articles can change upon visiting the site but only when there is a new article added.
The issue is I have logic that uses mt_rand to generate random numbers within a range (to fit in the layout grid), is there a way I can pass in a seed (planning to use the newest article id) so that the random numbers are consistent until a new article is introduced? I wanted to use mt_srand but there doesn’t seem to be an easy way to limit the random number within a range.
Thanks.
mt_srand() is used to set your seed and mt_rand() takes in a min and max if you want to set the range. Basically something like:
Note: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically.