Jake,

> This worked.. somewhat.. here is what I want to do though.
> 
> I have two people checking the same email address. I want to break up the
> emails 50/50 to each person. What values can I put into the random number
> generator so that I can get closer to 50/50. I just set up a test page with:
> 
> $rand = rand(1, 501);
> 
> echo $rand;
> 
> if ($rand % 2 == 0)
>   echo "even";
> else
>   echo "odd";
> 
> 
> and I'm getting a lot more evens than odds, so the one person would get more
> emails than the other. Is there any substitution to rand that I could use to
> get one message to go to one person, then the next to the other? I'd like it
> to be as close to 50/50 as possible.

Is there any way you can save state?  That is, can you keep track of who
got the last one, and use that to determine who should get the next one?

Otherwise, why not just rand() between 1 and 2?   rand(1,2) will, on
average, give you as many 1s as 2s (like flipping a coin).  There will
likely be runs of 1 or 2, but over time, doing rand() with two possible
values versus rand() with 501 values will not be significantly
different.

In fact, since there is one more odd than even between 1 and 501
(inclusive), you will be getting slightly more odds than evens with that
range than you will with a range of 1 and 2.

Also, which PHP version are you using?  If before 4.2.0, you should seed
the random number generator with srand().  If you are using 4.2.0 or
greater, and still seeing non-random behavior, I don't really have an
answer.

-- 
[ joel boonstra | gospelcom.net ]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to