# Random Negative or Possitive

**URL:** <https://forum.kirupa.com/t/random-negative-or-possitive/28615>\
**Category:** flash\
**Created:** [August 15, 2003, 6:11pm UTC](https://forum.kirupa.com/t/random-negative-or-possitive/28615 "2003-08-15T18:11:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thinker2501](https://avatars.discourse-cdn.com/v4/letter/t/e0b2c6/32.png) [@Thinker2501](https://forum.kirupa.com/u/Thinker2501)\
**Post date:** [August 15, 2003, 6:11pm UTC](https://forum.kirupa.com/t/random-negative-or-possitive/28615/1 "2003-08-15T18:11:44Z")

</div>

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?👁

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 15, 2003, 6:14pm UTC](https://forum.kirupa.com/t/random-negative-or-possitive/28615/2 "2003-08-15T18:14:09Z")

</div>

rand = (random(2)) ? 1 : -1;

or

rand = (Math.random() \< .5) ? 1 : -1;

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 15, 2003, 9:53pm UTC](https://forum.kirupa.com/t/random-negative-or-possitive/28615/3 "2003-08-15T21:53:46Z")

</div>

thanks, you’re the shizit sen :esmirk: Would you mind explaining the code, I get the Math.random but not the other stuff. Thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 15, 2003, 11:28pm UTC](https://forum.kirupa.com/t/random-negative-or-possitive/28615/4 "2003-08-15T23:28:07Z")

</div>

?: 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;
