Forum Moderators: coopster

Message Too Old, No Replies

Simple Random Test Using PHP

         

rogerd

12:26 am on Dec 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm looking at doing some simple split-run testing on pages coded in PHP. In essence, my proposed logic is very simple:

Choose Random Value between 0 and 1;
If Random Value is between 0 and .4, Run Script A, else Run Script B;

I've searched prewritten scripts fairly extensively, but all I'm finding are more complex split test scripts that use cookies or sessionIDs to keep track of which group a user is in. I have no tracking needs (that is done by an ad script) and I don't care if a visitor gets split A on one page and B on the next. All I need is to ensure I get a random, or pseudorandom, distribution of values so that I execute the two scripts in the proportion that I want.

Does what I'm trying to do make sense? Is there a randomizing function that can give me a reasonable distribution of values?

PeteM

12:59 pm on Dec 6, 2005 (gmt 0)

10+ Year Member



Not sure if I fully understand your question but

rand(0, 1);

will return a random number between 0 and 1.

Pete

LeChuck

1:23 pm on Dec 6, 2005 (gmt 0)

10+ Year Member



I don't think that does it, he probably wants something like

$num=rand(0,9);
if($num<5) {
include "test1.php";
} else {
include "test2.php";
}

If that's the case then you can't find any premade scripts because it's too simple... :)

rogerd

2:06 pm on Dec 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> because it's too simple

I'm sure that's the case, I guess what I was searching for was more of a code snippet than a script; it seems like a common enough application, but my search parameters must not have been very good. Thanks, LeChuck.

PeteM

5:14 pm on Dec 7, 2005 (gmt 0)

10+ Year Member



Fewer commands still would be...

include "test'.rand(1,2).'.php";

Pete

LeChuck

6:36 pm on Dec 7, 2005 (gmt 0)

10+ Year Member



But then you can't vary the probabilities.

And it's not exactly the kind of coding that I'd enjoy reading through a thousand lines of... :)