Theorems Posted December 19, 2017 Share Posted December 19, 2017 Hello, I am trying to add gaussian randoms to my script. I started using: int dynamicReturn = (int) ((rand.nextGaussian()*deviation)+mean); but the issue with that is the Gaussian random will not always stay within the deviation variable. To fix this I did: int dynamicReturn; do { dynamicReturn = (int) ((rand.nextGaussian()*deviation)+mean); }while(dynamicReturn < (mean-deviation) || dynamicReturn > (mean+deviation)); which works but because that would make it skip generated numbers outside of the range, I'm wondering if that would throw off my gaussian distribution? If so, what would be a better approach to use that would still lock all the values within my deviation? Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 19, 2017 Share Posted December 19, 2017 7 minutes ago, Theorems said: Hello, I am trying to add gaussian randoms to my script. I started using: int dynamicReturn = (int) ((rand.nextGaussian()*deviation)+mean); but the issue with that is the Gaussian random will not always stay within the deviation variable. To fix this I did: int dynamicReturn; do { dynamicReturn = (int) ((rand.nextGaussian()*deviation)+mean); }while(dynamicReturn < (mean-deviation) || dynamicReturn > (mean+deviation)); which works but because that would make it skip generated numbers outside of the range, I'm wondering if that would throw off my gaussian distribution? If so, what would be a better approach to use that would still lock all the values within my deviation? the way you're doing it is fine, but you'll want to make it within 3 standard deviations to have a gaussian distribution - something like 68% of values are within 1 deviation, 95% in 2, 99.7% in 3 deviations if i remember correctly Quote Link to comment Share on other sites More sharing options...
Theorems Posted December 19, 2017 Author Share Posted December 19, 2017 22 minutes ago, Team Cape said: the way you're doing it is fine, but you'll want to make it within 3 standard deviations to have a gaussian distribution - something like 68% of values are within 1 deviation, 95% in 2, 99.7% in 3 deviations if i remember correctly Interesting, I have not seen anything done like that before. Doesn't .nextGaussian() give you a Gaussian distribution all by itself without you adding multiple deviations? Quote Link to comment Share on other sites More sharing options...
dreameo Posted December 19, 2017 Share Posted December 19, 2017 (edited) 51 minutes ago, Team Cape said: the way you're doing it is fine, but you'll want to make it within 3 standard deviations to have a gaussian distribution - something like 68% of values are within 1 deviation, 95% in 2, 99.7% in 3 deviations if i remember correctly That's what nextGaussian() does @op Just wondering why you are trying to force your values to be within one SD? To further explain, if you're forcing all the 'random' values to be within one SD, then that 68 % of the population all have an equal chance of being selected which goes back to a flat distribution (each element has same probability of being selected) Edited December 19, 2017 by dreameo Quote Link to comment Share on other sites More sharing options...
Theorems Posted December 19, 2017 Author Share Posted December 19, 2017 (edited) 19 minutes ago, dreameo said: That's what nextGaussian() does @op Just wondering why you are trying to force your values to be within one SD? To further explain, if you're forcing all the 'random' values to be within one SD, then that 68 % of the population all have an equal chance of being selected which goes back to a flat distribution (each element has same probability of being selected) Yeah so it would destroy the Gaussian distribution, that's what I kinda thought might happen. The whole reason I was trying to do it like that in the first place is that I wanted to use it as the return value of my script, which I didn't want to be a zero. edit: was doing some reading and saw this "There is theoretically no absolute minimum and maximum value that can occur in a normal distribution." So would it really become a flat distribution if you were to just "cut" off the tips of the bell curve of random numbers generated? Doesn't quite make sense to me.. Edited December 19, 2017 by Theorems Quote Link to comment Share on other sites More sharing options...
dreameo Posted December 19, 2017 Share Posted December 19, 2017 2 minutes ago, Theorems said: Yeah so it would destroy the Gaussian distribution, that's what I kinda thought might happen. The whole reason I was trying to do it like that in the first place is that I wanted to use it as the return value of my script, which I didn't want to be a zero. Well, unless your standard deviation is incredibly high (relative to the mean), it would almost never be 0. Quote Link to comment Share on other sites More sharing options...
Theorems Posted December 19, 2017 Author Share Posted December 19, 2017 (edited) 4 minutes ago, dreameo said: Well, unless your standard deviation is incredibly high (relative to the mean), it would almost never be 0. See my edit from my last comment. Also at a mean of 600 and deviation of 300 I was getting some numbers below 0 rarely, but I wouldn't say almost never. Thanks for helping me understand this. Edited December 19, 2017 by Theorems Quote Link to comment Share on other sites More sharing options...
dreameo Posted December 19, 2017 Share Posted December 19, 2017 (edited) 10 minutes ago, Theorems said: See my edit from my last comment. Also at a mean of 600 and deviation of 300 I was getting some numbers below 0 rarely, but I wouldn't say almost never. Thanks for helping me understand this. Yea so that's fairly high lol. 0 Is within 2 SD which is (97-68 = 27/2 = 13.5) 13.5% probability of occurring. I think this math is wrong actually but you get the idea. 18 minutes ago, Theorems said: Yeah so it would destroy the Gaussian distribution, that's what I kinda thought might happen. The whole reason I was trying to do it like that in the first place is that I wanted to use it as the return value of my script, which I didn't want to be a zero. edit: was doing some reading and saw this "There is theoretically no absolute minimum and maximum value that can occur in a normal distribution." So would it really become a flat distribution if you were to just "cut" of the tips of the bell curve of random numbers generated? Doesn't quite make sense to me.. You're only accepting a range of elements to whom all have the same odds of being selected. So let me demonstrate: 0 mean, 1 std. -1 and 1 have the same odds of being generated. (1 std vs 1 std) -1 and 2 don't have the same odds of being generated. (1 std vs 2 std) Therefore, any element within 1 std has the same odds of being generated. Since you are confining them to being within 1 std, then it goes to a flat distribution. lol, someone can double check on my work tho Edited December 19, 2017 by dreameo 1 Quote Link to comment Share on other sites More sharing options...
Theorems Posted December 19, 2017 Author Share Posted December 19, 2017 @dreameo Okay thanks, that makes more sense, although with my example (600 mean, 300 deviation) I think the numbers should still cluster around the mean of 600 even if I only accept numbers within a range which would still make 600 more likely to be generated than 300 or 900. So it wouldn't be a fully normal distribution, but neither would it be flat, if I am understanding correctly. Quote Link to comment Share on other sites More sharing options...
dreameo Posted December 19, 2017 Share Posted December 19, 2017 (edited) 22 minutes ago, Theorems said: @dreameo Okay thanks, that makes more sense, although with my example (600 mean, 300 deviation) I think the numbers should still cluster around the mean of 600 even if I only accept numbers within a range which would still make 600 more likely to be generated than 300 or 900. So it wouldn't be a fully normal distribution, but neither would it be flat, if I am understanding correctly. Yea, I tested this. Looks to be true. Numbers closer to the mean are more likely to be generated regardless if they are within the same std. What I described would be a normal distribution with flat tops lol. Edited December 19, 2017 by dreameo 1 Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 19, 2017 Share Posted December 19, 2017 (edited) 1 hour ago, dreameo said: That's what nextGaussian() does He's only checking within 1 deviation - if he wants to generate a curve that's actually close to gaussian, he'll need to check 3, or else he'll just have the 68%. See the example that he posted above. 1 hour ago, Theorems said: Yeah so it would destroy the Gaussian distribution, that's what I kinda thought might happen. The whole reason I was trying to do it like that in the first place is that I wanted to use it as the return value of my script, which I didn't want to be a zero. edit: was doing some reading and saw this "There is theoretically no absolute minimum and maximum value that can occur in a normal distribution." So would it really become a flat distribution if you were to just "cut" off the tips of the bell curve of random numbers generated? Doesn't quite make sense to me.. Computationally, it's not worth dealing with values that have the potential to be incredibly outlandish (i.e. 5000, when you're looking for a value from 4000-4500). the chances of such a value occurring are incredibly small, but regardless, you only have to check one or two boolean statements, so it's worth it to just make the check. 2 hours ago, Theorems said: Interesting, I have not seen anything done like that before. Doesn't .nextGaussian() give you a Gaussian distribution all by itself without you adding multiple deviations? It does do that by itself, that's its purpose, but you're only checking 1 deviation in your loop: }while(dynamicReturn < (mean-deviation) || dynamicReturn > (mean+deviation)); You'll want to make that 3*deviation in both cases. Edited December 19, 2017 by Team Cape Quote Link to comment Share on other sites More sharing options...