meanTruncatedNormal function

num meanTruncatedNormal(
  1. num min,
  2. num max,
  3. num mean,
  4. num stdDev
)

Returns the mean of a truncated normal distribution with minimum value min, maximum value max, mean mean, and standard deviation stdDev.

Implementation

num meanTruncatedNormal(num min, num max, num mean, num stdDev) {
  final alpha = (min - mean) / stdDev;
  final beta = (max - mean) / stdDev;
  return mean +
      stdDev *
          (stdNormalPdf(alpha) - stdNormalPdf(beta)) /
          (stdNormalCdf(beta) - stdNormalCdf(alpha));
}