eelixduppy
 Msg#: 10772 posted 8:29 pm on Nov 12, 2005 (gmt 0) 
Just thinking about it quickly i think i found a solution to your problem.... now i haven't tried anything out but im sure it will work. When the page loads it should retrieve the number of previous visitors to your site from a text file or database. Now depending on what ratio you are using, in your example 3:7, you add the two numbers (i.e. 3+7=10). Now you take the amount of visitors to your site and do something like: $modulus = $visitors % 10; if($modulus < 4) { do something } else if($modulus > 3) { do something else } As i said i haven't tried it to see if its flawless but it should work! Good luck...

charlier
 Msg#: 10772 posted 8:36 pm on Nov 12, 2005 (gmt 0) 
You could also generate a random number between 1 and 10, if the number is less the 4 you do the 3x case otherwise the 7x case. You can input your limit from a config file to set it to 1:9 2:8 etc.

dmorison
 Msg#: 10772 posted 8:42 pm on Nov 12, 2005 (gmt 0) 
If you're happy for the distribution to average out to the required ratio over time then you can do it mathematically...
$ratio = intval((3/7) * 100); if (rand(1,100) < $ratio) { // 3's content } else { // 7's content }



ergophobe
 Msg#: 10772 posted 6:09 pm on Nov 13, 2005 (gmt 0) 
Actually, as I read it, the OP wants 3/10 and 7/10 (the ratio is "3 to 7" not "3 out of 7"), so you use charlier's logic and dmorison's code and you have: if (rand(1,10) < 4) { //30% } else { // 70% }

panos
 Msg#: 10772 posted 11:02 pm on Nov 13, 2005 (gmt 0) 
It's not that simple guys, what you are suggesting can be true only for large number [en.wikipedia.org] of trials (code executions) and even in that case we will never have exactly 3/10 and 7/10. If a coin is flipped once the probability that it lands heads up is 0.5 or 50%. But if it is flipped 10 times the probability that it lands heads up exactly 5 times is not 0.5 but using the Binomial Probability Formula [google.com]: (10!/5!(105)!) (1/2)^5) (1/2)^5 = 0.246 As we increase the number of tosses the relative frequency (heads up/number of tosses) tends to vary less and stay near 0.5, or 50%. So we need a large number of trials to obtain our theoretical probability (0.5). If your code can not be executed thousands of times a day you can use the binomial probability formula. Use as number of trials the times your code will be executed from statistical analysis of the last days or months

ergophobe
 Msg#: 10772 posted 6:56 pm on Nov 14, 2005 (gmt 0) 
As dmorison said If you're happy for the distribution to average 
 If it has to be exactly three out of every ten, then he will need some sort of counter system. If he wants a 3 in 10 chance of the page coming up, the pseudorandom number generator should get pretty close to that.

