explorers' club

explorations in dev, science, sci-fi, games, and other fun stuff!

Note to Self: Odds, Evens, -1 & 1

2 Comments

[BEST]

var isOdd:Boolean = Boolean( numberToCheck & 1 );
//for random odd/even
var isOdd:Boolean = Boolean( Math.round( Math.random() ) & 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;
Advertisements

2 thoughts on “Note to Self: Odds, Evens, -1 & 1

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

  2. var isOdd:Boolean = number & 1;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s