Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. private double getNormalDistributed(double? mean, double? standardDev)
  2. {
  3. //This has to happen here since mean and standard deviation can be different for each call, and those values are readonly in the Normal
  4. MathNet.Numerics.Distributions.Normal normalDistribution = new MathNet.Numerics.Distributions.Normal((double)mean, (double)standardDev, random);
  5.  
  6. double result = normalDistribution.Sample();
  7.  
  8. //Force the result to be not more than 2 standard deviations away from the mean
  9. if (result > mean + 2 * standardDev) result = (double)mean + 2 * (double)standardDev;
  10. if (result < mean - 2 * standardDev) result = (double)mean - 2 * (double)standardDev;
  11.  
  12. return result;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement