Note to Self: Odds, Evens, -1 & 1
2 Comments so far
Leave a comment
Sunday, May 10, 2009, 7:11 am
Filed under: Uncategorized | Tags: actionScript, development, math, note to self, tips
Filed under: Uncategorized | Tags: actionScript, development, math, note to self, tips
[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
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>

or just
Comment by Richard Lord Sunday, May 10, 2009 @ 10:12 amMath.round( Math.random() ) == 0 ? 1 : -1
Comment by David Holz Sunday, May 24, 2009 @ 7:59 amvar isOdd:Boolean = number & 1;