explorers’ club


Note to Self: Odds, Evens, -1 & 1
Sunday, May 10, 2009, 7:11 am
Filed under: Uncategorized | Tags: , , , ,

[BEST]

*however it does throw a compiler warning 3590: int used where a Boolean value was expected.  The expression will be type coerced to Boolean.

var isOdd:Boolean = numberToCheck & 1;

[BETTER]

Math.round( Math.random() ) == 0 ? 1 : -1;

[GOOD]

odd or even  = Math.round(Math.random() * 100) % 2 == 0 ? "even" : "odd";
-1 or 1 = Math.round(Math.random() * 100) % 2 == 0 ? 1 :- 1;

2 Comments so far
Leave a comment

or just
Math.round( Math.random() ) == 0 ? 1 : -1

Comment by Richard Lord

var isOdd:Boolean = number & 1;

Comment by David Holz




Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>