View Full Version : Negative random numbers
Chris
September 9th, 2001, 12:14 AM
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
upuaut8
September 9th, 2001, 12:33 AM
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. ;)
Chris
September 9th, 2001, 01:53 PM
Ok thanks. I got it to work.
Chris
suprabeener
September 9th, 2001, 03:27 PM
here's a cleaner method:
num = Math.random()*200-100;
this makes num equal some number b/w -100 and 100.
upuaut8
September 11th, 2001, 05:58 AM
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
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.