# Negative random numbers

**URL:** <https://forum.kirupa.com/t/negative-random-numbers/3809>\
**Category:** programming\
**Created:** [September 9, 2001, 3:14am UTC](https://forum.kirupa.com/t/negative-random-numbers/3809 "2001-09-09T03:14:57Z")\
**Posts on this page:** 5\
**Page:** 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:** [September 9, 2001, 3:14am UTC](https://forum.kirupa.com/t/negative-random-numbers/3809/1 "2001-09-09T03:14:57Z")

</div>

Is to possible to generate negative and positive random numbers in Flash? I know how to generate numbers from say 0 to 100 but what about generating random numbers from say… -100 to 100? I havent heard of this before but then again this is an unusual request.

Any help appreciated.

Chris

---

<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:** [September 9, 2001, 3:33am UTC](https://forum.kirupa.com/t/negative-random-numbers/3809/2 "2001-09-09T03:33:32Z")

</div>

I don’t know if it’s directly possible… but certainly a work around could be produced.

negpos=random(2)  
if negpos=0  
neg=true  
totalRandom=random(100)  
totalRandom=TotalRandom+1  
if neg=true  
totalRandom=(totalRandom)\*-1

bear with me if that example doesn’t work… I’m not much of a programer yet… none the less it should be something similar to that. 😉

---

<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:** [September 9, 2001, 4:53pm UTC](https://forum.kirupa.com/t/negative-random-numbers/3809/3 "2001-09-09T16:53:17Z")

</div>

Ok thanks. I got it to work.

Chris

---

<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:** [September 9, 2001, 6:27pm UTC](https://forum.kirupa.com/t/negative-random-numbers/3809/4 "2001-09-09T18:27:03Z")

</div>

here’s a cleaner method:

num = Math.random()\*200-100;

this makes num equal some number b/w -100 and 100.

---

<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:** [September 11, 2001, 8:58am UTC](https://forum.kirupa.com/t/negative-random-numbers/3809/5 "2001-09-11T08:58:10Z")

</div>

really… Sweet…

See that’s what I love about flash… there are always a dozen ways of doing something…

Be forwarned… I only took algebra as my top level math… with math, I’m stumbling around in the dark.

Thanks again suprabeener
