Run every x amount of time

I have to display a block 30 percent of the time. So for example: for every 10 people that visit my page, I want to display this block only 3 times.

Anyone have any thoughts on how to do this? I can control if my block get’s display via PHP but how can I make it only perform 30 percent of the time.

It depends, do you want to show it once for every three visits, or give each visit a 30% chance of seeing it?

Once every 3 visits.

1.) create a database table called “visit_counter” with fields id_visit, visit_count; visit_count starts at 0

2.) when a visitor comes to the page with the “block” add 1 to the visit_count field in “visit_counter” table, so after first visit there is number 1, after second visit there is number 2 etc.

3.) each visit to the page, get the value of visit_count from database and perform:

if ($visit_count % 3 == 0){
// display block
}

Thats it.

That is the same way I’m thinking. I guess there is no way of doing it other than storing the count in the database or a file.