Page 1 of 1

sum of multiple FRand()

Posted: Tue Jan 02, 2024 12:02 pm
by Barbie
Is FRand() + FRand() + FRand() + FRand() statistically the same as 4 * FRand()?

Re: sum of multiple FRand()

Posted: Tue Jan 02, 2024 1:21 pm
by Buggie
No, it is not.
4 random value is not same as one value increased in 4 times.

One value increase in 4 times keep all parameters increased in 4 times.

Sum of 4 value use different params.

For illustrate this, let's replace 4 with some big number like 100 000.

Sum of 100 000 random values very likely be 100 000 times of median for this random value.
When 100 000 multiplied on single random value still be random value, uniformly distributed in some range.

OFC for smaller N it less noticeable and for N = 1 effect is gone.

Re: sum of multiple FRand()

Posted: Tue Jan 02, 2024 3:16 pm
by Barbie
Thanks. I stumbled over that in class ThingFactory:

Code: Select all

else //timeDistribution is gaussian
	nextTime = 0.5 * (FRand() + FRand() + FRand() + FRand()) * interval;
what tries to approximate exp(-x²).

Re: sum of multiple FRand()

Posted: Tue Jan 02, 2024 3:36 pm
by Buggie
It is Irwin-Hall distribution:

https://math.stackexchange.com/question ... -variables

https://en.wikipedia.org/wiki/Irwin%E2% ... stribution   
Auto merged new post submitted 9 minutes later
If they really need use gaussian distribution from uniform, they should use Box-Muller transform:
https://en.wikipedia.org/wiki/Box%E2%80 ... _transform   
Auto merged new post submitted 1 minute later
There you can more practical advice's about how do that:
https://stackoverflow.com/questions/756 ... stribution

Re: sum of multiple FRand()

Posted: Tue Jan 02, 2024 3:51 pm
by _21
At N=4 the distribution is quite similar to a Gaussian, for a video game its a practical technique.

Re: sum of multiple FRand()

Posted: Tue Jan 02, 2024 3:59 pm
by Buggie
I found this for 3:

https://www.researchgate.net/figure/Irw ... _319887464
Irwin-Hall-distribution-with-n3-and-the-matching-normal-distribution-with-mean-3-2-and.jpg
Irwin-Hall distribution with n=3 and the matching normal distribution with mean 3/2 and variance 1/4.
   
Auto merged new post submitted 6 minutes later
According to wiki - best use sum of 12 values minus 6:
https://en.wikipedia.org/wiki/Irwin%E2% ... stribution   
Auto merged new post submitted 1 hour 18 minutes later
Also original formula is more like as Bates ditrubution:
https://en.wikipedia.org/wiki/Bates_distribution

(X + X + X + X) / 4 * (2 * Interval).