tags:

views:

47

answers:

2

How can I show something on 75% of requests, so that on average, every four page requests would result in three pages showing it, and one not.

this is a translation of this question!...

i dont know how it working with 70%

now how i can show in example echo iam; in a page in 70% percent

this mean it will appear 3 times and one not

+1  A: 

I don't know whether I got you correctly but you can do this:

$i = rand(0,3);
if($i < 3) {
    echo 'foo';
}

This will echo foo in 75% of all visits.

Felix Kling
but this can echo 'foo'; 4 times because its random
moustafa
@moustafa: Yes, but according to the law of big numbers, in the long run you will get 75%.
Felix Kling
+1  A: 

The only fool proof way I can think to do this is:

if (($pageHits % 10) < 7)
    echo 'iam';
Mark Tomlin
what $pageHits mean
moustafa
Page hits is the number of times that page has been requested. You would have to get this value yourself, in your own way.
Mark Tomlin