• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Calculating True Variance issue...

Falidell

Grizzled Veteran
May 22, 2009
645
78
34
Mesa,Az,USA
ok here is my problem. i want to calculate true variance.
my current equation is this:


RP is the RandomPause result
RP=rand(PauseTime)+((rand(Variance)+1)-rand(Variance))

i added the +1 becuase
say i had a variance of 5
without the +1 it would be -5/+4/variance
however now it's
-4/+5 variance

but i want it to be -5/+5

now before some of you respond Unrealscript rand() only does random 0 to x so for ex. rand(7) only gives a a possible result of 1-6 or 1-7 if you do rand(7)+1

i'm pretty sure there isn't an exact method of calculating True Variance. in scripting at any rate. but jsut in case i want to know what you guys thoughts on this matter is.

Edit: acually it's not that big of a deal i'm gona go with this current equation. tho you guys can still answer if you want =D
 
Last edited:
True Variance is the calculation of Variance.

Just putting rand(8) doesn't give a True Variance result of -8to8 it only gives a result of 1-7 which is called Add Variance because it only adds

so inorder to get a True variance you have to make an equation inorder to get
-8to8 which is what i want.

Rand(PauseTime)+Rand(Variance*2+1)-Variance

Pausetime is the time i want to pause
Variance is the amount of time Varied from the Pausetime

I want the Pausetime to be 10
and the Variance to be 5

the Equation yeilds
10 +/- 5 so anywhere from 5-15 seconds
 
Upvote 0
In that case you want to set a constant base value (not a random value), else you may end up with a negative result. For example the result of the first rand may be 0, and then you are possibly subtracting 5 from it resulting in -5, outside of the range you expected.

Value = BaseValue + Rand(Variance) - HalfVariance

Of course, what Marco suggested will be best for readability and no doubt performance-wise. :)
 
Upvote 0
huh never knew there was such a thing a RandRange

Thanks Yet again MArco!!

and yes i have just started to notice that too ben =(
so with the Rand Equation i put in a safety protocol
in postbeginplay

if the Variance input is Larger then the PauseTime input
the it changes the Variance to PauseTime-1

so that way the lowest posible time would be 1 second
 
Last edited:
Upvote 0