![]() |
Randomly running some code
I have some ad code, but only want to show it with a 1 in 10 chance. The code is:
Code:
<div data-type="ad" data-publisher="abc.mysite.site" data-zone="ron" data-format="728x90"></div> Is there any vbulletin code that allows me to do this? Thanks, Jon |
I think this would work:
Code:
<if condition="TIMENOW%10==0"> Basically, whenever the current time (in seconds) ends in 0 it will show. |
Clever idea, thanks! I will try that. :)
--------------- Added [DATE]1382625240[/DATE] at [TIME]1382625240[/TIME] --------------- Seems to work. :) Would be nice to work out how to vary the probability of display. e.g 1 in 7 or whatever. So, I could say decide to set it to 1 in 7 or 1 in 5 etc. |
Quote:
|
Yeah, what squidsk said. I simplified the explanation a little, the code actually divides the unix time (seconds since Jan 1 1980 or something like that) by ten and checks that the remainder is 0, which happens when the last digit is 0 (since we're dividing by 10). But you can just as easily divide by 7 (or whatever) and check for a remainder of 0 to get a 1 in 7 chance.
|
I've tried using 2 and it showed my ads 1 in 2 chance. But when I tried 4 or 7, it didn't show 1 in 4 or 1 in 7 times. Maybe the maths is a bit out somehow? Do I need to clip off the decimals or something?
|
Hmm...'%' should divide integers and return the remainder, so I don't think decimals should matter. So you're saying condition="TIMENOW%7==0" doesn't work right?
|
I am trying 1 in 4 right now. TIMENOW%4==0
See it in action (or not as the case may be!):http://access-programmers.co.uk/foru...ar#post1301767 The third post has a 300x250 advert. There should be another one appearing to the right of that one 1 in 4 times. But it doesn't. |
OK, I ran a test and it seems to work. Are you saying that the exact code works with 10 or 2 but not 4 or 7 (I guess I'm saying, are you sure there's not a typo)? If you do this (add the 1|| in the condition):
Code:
<if condtion="1||TIMENOW%4==0"> then it should show every time and you can make sure there's not something else wrong. The only other thing I can think of is that it's not exactly random because it's based on the time, so if for example you have it set to 4 and you constantly hit reload, and the page happens to take about 4 seconds to load each time, you may end up with something that looks like it's not a 1 in 4 chance. |
My code is:
Code:
<if condition="TIMENOW%4==0"> |
All times are GMT. The time now is 04:58 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|