public void Uniform(
            int sampleSize,
            double[] destinationArray,
            int destinationIndex,
            double lowerBound,
            double upperBound)
        {
            ProbabilityDistribution.ValidateSampleInput(
                sampleSize,
                destinationArray,
                destinationIndex);

            UniformDistribution.ValidateBounds(
                lowerBound,
                upperBound);

            unsafe
            {
                fixed(double *destinationPointer = &destinationArray[destinationIndex])
                {
                    SafeNativeMethods.VSL.vdRngUniform(
                        0,
                        this.descriptor.DangerousGetHandle().ToPointer(),
                        sampleSize,
                        destinationPointer,
                        lowerBound,
                        upperBound);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UniformDistribution"/> class
        /// defined on an interval having the specified lower and upper bounds.
        /// </summary>
        /// <param name="lowerBound">The interval lower bound.</param>
        /// <param name="upperBound">The interval upper bound.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="upperBound"/> is not greater
        /// than <paramref name="lowerBound"/>.
        /// </exception>
        public UniformDistribution(double lowerBound, double upperBound)
        {
            UniformDistribution.ValidateBounds(lowerBound, upperBound);

            this.lowerBound = lowerBound;
            this.upperBound = upperBound;
        }
        public double Uniform(
            double lowerBound,
            double upperBound)
        {
            UniformDistribution.ValidateBounds(
                lowerBound,
                upperBound);

            double sample;

            unsafe
            {
                SafeNativeMethods.VSL.vdRngUniform(
                    0,
                    this.descriptor.DangerousGetHandle().ToPointer(),
                    1,
                    &sample,
                    lowerBound,
                    upperBound);
            }

            return(sample);
        }
        public int DiscreteUniform(
            int lowerBound,
            int upperBound)
        {
            UniformDistribution.ValidateBounds(
                lowerBound,
                upperBound);

            int sample;

            unsafe
            {
                SafeNativeMethods.VSL.viRngUniform(
                    0,
                    this.descriptor.DangerousGetHandle().ToPointer(),
                    1,
                    &sample,
                    lowerBound,
                    upperBound);
            }

            return(sample);
        }