On Fri, 2004-01-16 at 13:17, Jake McHenry wrote:
I have a random number being generated from 1 to 501, is there an easy way for me to
tell if the result is an odd or even number?
Yep. The modulus operator (%). Your number mod 2 will be 1 if it is odd
and 0 if it is even.
function isOdd ($value) {
return (int)$value % 2 ? true : false;
}
Returns true/false if the value is odd. Also rounds down floating point numbers given
as the test value.
-Jeremy
-Original Message-
From: Jake McHenry [mailto:[EMAIL PROTECTED]
Sent: Friday, January 16, 2004
On Fri, Jan 16, 2004 at 02:30:59PM -0600, Jeremy wrote:
function isOdd ($value) {
return (int)$value % 2 ? true : false;
}
Returns true/false if the value is odd. Also rounds down floating point numbers
given as the test value.
No need to explicitly state true and false. Just
- Original Message -
From: joel boonstra [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, January 16, 2004 3:35 PM
Subject: Re: [PHP] odd and even numbers
On Fri, Jan 16, 2004 at 02:30:59PM -0600, Jeremy wrote:
function isOdd ($value) {
return (int)$value % 2 ? true : false
On Fri, 2004-01-16 at 15:17, Jake McHenry wrote:
I have a random number being generated from 1 to 501, is there an easy way for me to
tell if the result is an odd or even number?
(1 number) ? odd : even;
E.g.
?php
$i=1;
echo 'pre';
while($i 10) {
(1 $i) ? print($i . ' is odd') :
- Original Message -
From: joel boonstra [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, January 16, 2004 3:35 PM
Subject: Re: [PHP] odd and even numbers
On Fri, Jan 16, 2004 at 02:30:59PM -0600, Jeremy wrote:
function isOdd ($value) {
return (int)$value % 2 ? true : false
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:
- Original Message -
From: Katie Dewees [EMAIL PROTECTED]
To: Jake McHenry [EMAIL PROTECTED]
Sent: Friday, January 16, 2004 4:44 PM
Subject: RE: [PHP] odd and even numbers
Can you just set a value somewhere (in a flat file, or a database) to 1 or
2. 1 can represent person number 1, 2
- Original Message -
From: joel boonstra [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, January 16, 2004 4:54 PM
Subject: Re: [PHP] odd and even numbers
Jake,
This worked.. somewhat.. here is what I want to do though.
I have two people checking the same email address. I
9 matches
Mail list logo