Dodona gives you answers

How do I program a random value of either 1 or -1?

leave a comment »

In in my case actionscript or any other programming language, you might want to code a random value to be either 1 or -1, for example to randomly have an object rotate clockwise or counter-clockwise. This is how you can get this value in actionscript:

var randomDirection:Number = Math.round(Math.random())*2-1;

Now the randomDirection variable will always be either 1 or -1.

Written by lutsen

December 8, 2009 at 11:34 pm

Posted in Actionscript

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

%d bloggers like this: