예제 #1
0
        /// <summary>
        /// Returns a random double value according to the specified configuration.
        /// </summary>
        /// <param name="randomValueCfg">The random unsigned value configuration.</param>
        /// <param name="rand"></param>
        public static double NextDouble(this Random rand, URandomValueSettings randomValueCfg)
        {
            double value;

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

            case RandomCommon.DistributionType.Gaussian:
                if (randomValueCfg.DistrCfg != null)
                {
                    UGaussianDistrSettings gaussianCfg = randomValueCfg.DistrCfg as UGaussianDistrSettings;
                    value = rand.NextRangedGaussianDouble(gaussianCfg.Mean, gaussianCfg.StdDev, randomValueCfg.Min, randomValueCfg.Max);
                }
                else
                {
                    throw new ArgumentException($"A specific configuration of the Gaussian distribution is missing.", "randomValueCfg");
                }
                break;

            case RandomCommon.DistributionType.Exponential:
                if (randomValueCfg.DistrCfg != null)
                {
                    UExponentialDistrSettings exponentialCfg = randomValueCfg.DistrCfg as UExponentialDistrSettings;
                    value = rand.NextRangedExponentialDouble(exponentialCfg.Mean, randomValueCfg.Min, randomValueCfg.Max);
                }
                else
                {
                    throw new ArgumentException($"A specific configuration of the Exponential distribution is missing.", "randomValueCfg");
                }
                break;

            case RandomCommon.DistributionType.Gamma:
                if (randomValueCfg.DistrCfg != null)
                {
                    GammaDistrSettings gammaCfg = randomValueCfg.DistrCfg as GammaDistrSettings;
                    value = rand.NextRangedGammaDouble(gammaCfg.Alpha, gammaCfg.Beta, randomValueCfg.Min, randomValueCfg.Max);
                }
                else
                {
                    throw new ArgumentException($"A specific configuration of the Gamma distribution is missing.", "randomValueCfg");
                }
                break;

            default:
                throw new ArgumentException($"Unknown distribution type: {randomValueCfg.DistrType}.", "randomValueCfg");
            }
            return(value);
        }
예제 #2
0
        /// <summary>
        /// Returns random unsigned double according to specified settings.
        /// </summary>
        /// <param name="rand"></param>
        /// <param name="settings">Encapsulated settings</param>
        public static double NextDouble(this Random rand, URandomValueSettings settings)
        {
            double value;

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

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

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

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

            default:
                throw new InvalidOperationException($"Unknown distribution type {settings.DistrType}.");
            }
            return(value);
        }
예제 #3
0
 /// <summary>
 /// Returns a random double value.
 /// </summary>
 /// <remarks>
 /// Follows the Gaussian distribution.
 /// </remarks>
 /// <param name="distrCfg">Configuration of the unsigned Exponential distribution.</param>
 /// <param name="rand"></param>
 public static double NextExponentialDouble(this Random rand, UExponentialDistrSettings distrCfg)
 {
     return(NextExponentialDouble(rand, distrCfg.Mean));
 }