コード例 #1
0
        /// <summary>
        ///     Get a random number from a normal distribution in [min,max].
        /// </summary>
        /// <description>
        ///     Get a random number between min [inclusive] and max [inclusive] with probability matching
        ///     a normal distribution along this range. The width of the distribution is described by the
        ///     confidence_level_cutoff, which describes what percentage of the bell curve should be over
        ///     the provided range. For example, a confidence level cutoff of 0.999 will result in a bell
        ///     curve from min to max that contains 99.9% of the area under the complete curve. 0.80 gives
        ///     a curve with 80% of the distribution's area.
        ///     Because a normal distribution flattens of towards the ends, this means that 0.80 will have
        ///     more even distribution between min and max than 0.999.
        /// </description>
        /// <returns>
        ///     A random number between min [inclusive] and max [inclusive], with probability described
        ///     by the distribution.
        /// </returns>
        /// <param name="min">The min value returned [inclusive].</param>
        /// <param name="max">The max min value returned [inclusive].</param>
        /// <param name="confidence_level_cutoff">
        ///     The percentage of a standard normal distribution that should be represented in the range.
        /// </param>
        public static float RandomRangeNormalDistribution(
            float min,
            float max,
            ConfidenceLevel_e confidence_level_cutoff /*, float confidence_level_cutoff*/)
        {
            var mean = 0.5f * (min + max);

            // TODO formula for this?
            var z_score_cutoff = confidence_to_z_score[(int)confidence_level_cutoff];

            var new_width = (max - min) / 2.0f;
            var sigma     = new_width / z_score_cutoff;


            // Get random normal from Normal Distribution that's within the confidence level cutoff requested
            float random_normal_num;

            do
            {
                random_normal_num = RandomNormalDistribution(mean, sigma);
            } while ((random_normal_num > max) || (random_normal_num < min));

            // now you have a number selected from a bell curve stretching from min to max!
            return(random_normal_num);
        }
コード例 #2
0
	/// <summary>
	/// Get a random number from a normal distribution in [min,max].
	/// </summary>
	/// <description>
	/// Get a random number between min [inclusive] and max [inclusive] with probability matching
	/// a normal distribution along this range. The width of the distribution is described by the
	/// confidence_level_cutoff, which describes what percentage of the bell curve should be over
	/// the provided range. For example, a confidence level cutoff of 0.999 will result in a bell
	/// curve from min to max that contains 99.9% of the area under the complete curve. 0.80 gives
	/// a curve with 80% of the distribution's area.
	/// Because a normal distribution flattens of towards the ends, this means that 0.80 will have
	/// more even distribution between min and max than 0.999.
	/// </description>
	/// <returns>
	/// A random number between min [inclusive] and max [inclusive], with probability described
	/// by the distribution.
	/// </returns>
	/// <param name="min">The min value returned [inclusive].</param>
	/// <param name="max">The max min value returned [inclusive].</param>
	/// <param name="confidence_level_cutoff">
	/// The percentage of a standard normal distribution that should be represented in the range.
	/// </param>
	public static float RandomRangeNormalDistribution(float min, float max,
	                                                  ConfidenceLevel_e confidence_level_cutoff /*, float confidence_level_cutoff*/) {

		float mean = 0.5f * (min + max);
		
		// TODO formula for this?
		float z_score_cutoff = confidence_to_z_score[(int)confidence_level_cutoff];

		float new_width = (max - min) / 2.0f;
		float sigma = new_width / z_score_cutoff;


		// Get random normal from Normal Distribution that's within the confidence level cutoff requested
		float random_normal_num;
		do {
			random_normal_num = RandomNormalDistribution(mean, sigma);
			
		} while (random_normal_num > max || random_normal_num < min);

		// now you have a number selected from a bell curve stretching from min to max!
		return random_normal_num;

	}