I’m try to do something where I need a to randomly generate either a -1 or a 1. and nothing else. can anyone tell me how to do this?
rand = (random(2)) ? 1 : -1;
or
rand = (Math.random() < .5) ? 1 : -1;
thanks, you’re the shizit sen :esmirk: Would you mind explaining the code, I get the Math.random but not the other stuff. Thanks
?: is an if else condition (its in the actionscript help under symbols)
if the condition before the ? is true, the value after the ? is returned, otherwise, if the condition before the ? is false, the value after the : is returned. basically it equates to:
rand equals, if Math.random() < .5, then 1 else -1;