Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Randomness issue
Randomness issue
Randomness issue
We use metamod on our site, but I've had a small problem getting true randomness. If you refresh the page many times you won't really get 1 out of 13 odds, many times you'll get the same few modules again. The module is titled "More Branson Videos". http://www.bransonvisitortv.com/
Joomla version 1.5.14
Here's the code I'm using.
$r = rand(1,13); // get a random number: 1-13 inclusive
if ($r == 1) return 198;
if ($r == 2) return 199;
if ($r == 3) return 202;
if ($r == 4) return 203;
if ($r == 5) return 204;
if ($r == 6) return 205;
if ($r == 7) return 231;
if ($r == 8) return 243;
if ($r == 9) return 245;
if ($r == 10) return 244;
if ($r == 11) return 249;
if ($r == 12) return 251;
if ($r == 13) return 254;
Thanks
John
Re: Randomness issue
Hi John,
I think there could be 2 reasons for this:
1 - the rand() function is not as random as it should be (though honestly, I am surprised that it's as non-random as you are experiencing). You can use an alternative function that's supposed to be a lot better though: mt_rand(). So you can change your 1st line to this:
$r = mt_rand(1,13); // get a random number: 1-13 inclusive
2 - (more likely) I think you probably have the System Cache plugin activated. If you are caching entire pages with this plugin, then it's going to completely ignore any randomness, because the previous contents of the page are going to be used instead of this code being re-run. The System Cache is simply not smart enough to understand that modules may render themselves differently at different times, e.g. by randomness such as you are using, or even with things like a list of articles changing, in a mod_latest sort of module.
So, go to your Plugin Manager, and look for "System - Cache", and turn it off. Yes, there will be a performance hit, but that's a fact of life when you have dynamic content.
Hope that helps,
Stephen
ps. I'd be very interested to know if the rand()/mt_rand() thing was the problem. If so, I'll change the recipe in the Recipes section.
- Index
- » MetaMod
- » MetaMod General Support
- » Randomness issue
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7628
- Newest User:
- horlogekorting34
- Members Online:
- 1
- Guests Online:
- 136
- Online:
- uistr4qx
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked