Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

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

johnp
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

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.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Randomness issue

You can check it out now, seemed to improve with the code change.  System-cache was already off.  Thanks

johnp
Beginner Modder
ranks
useravatar
Offline
2 Posts
Administrator has disabled public posting

Re: Randomness issue

ok, that's good to know, thanks for reporting back.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5914
Total Posts Today:
1
User Info:
 
Total Users:
10816
Newest User:
sakmy567q
Members Online:
0
Guests Online:
127

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked