Exemple #1
0
        /// <summary>
        /// Returns random double according to specified settings.
        /// </summary>
        /// <param name="rand"></param>
        /// <param name="settings">Encapsulated settings</param>
        public static double NextDouble(this Random rand, RandomValueSettings settings)
        {
            double value;

            switch (settings.DistrType)
            {
            case DistributionType.Uniform:
                value = rand.NextRangedUniformDouble(settings.Min, settings.Max);
                break;

            case DistributionType.Gaussian:
                if (settings.DistrCfg != null)
                {
                    RandomValueSettings.GaussianDistrSettings gaussianCfg = settings.DistrCfg as RandomValueSettings.GaussianDistrSettings;
                    value = rand.NextFilterredGaussianDouble(gaussianCfg.Mean, gaussianCfg.StdDev, settings.Min, settings.Max);
                }
                else
                {
                    throw new Exception($"Configuration of Gaussian distribution is missing");
                }
                break;

            case DistributionType.Exponential:
                if (settings.DistrCfg != null)
                {
                    RandomValueSettings.ExponentialDistrSettings exponentialCfg = settings.DistrCfg as RandomValueSettings.ExponentialDistrSettings;
                    value = rand.NextFilterredExponentialDouble(exponentialCfg.Mean, settings.Min, settings.Max);
                }
                else
                {
                    throw new Exception($"Configuration of Exponential distribution is missing");
                }
                break;

            case DistributionType.Gamma:
                if (settings.DistrCfg != null)
                {
                    RandomValueSettings.GammaDistrSettings gammaCfg = settings.DistrCfg as RandomValueSettings.GammaDistrSettings;
                    value = rand.NextFilterredGammaDouble(gammaCfg.Alpha, gammaCfg.Beta, settings.Min, settings.Max);
                }
                else
                {
                    throw new Exception($"Configuration of Gamma distribution is missing");
                }
                break;

            default:
                throw new Exception($"Unknown distribution type {settings.DistrType}.");
            }
            if (settings.RandomSign)
            {
                value *= rand.NextSign();
            }
            return(value);
        }
Exemple #2
0
 /// <summary>
 /// Returns positive random double following the Gamma distribution.
 /// </summary>
 /// <param name="rand"></param>
 /// <param name="distrParams">Gamma distribution parameters</param>
 public static double NextGammaDouble(this Random rand, RandomValueSettings.GammaDistrSettings distrParams)
 {
     return(NextGammaDouble(rand, distrParams.Alpha, distrParams.Beta));
 }