Why not the Rnd function? Its statistically appropriate and built in. The only statistical fault it has is that first you have to seed it.. but.. ALL random number genrators have to do that. As such.. there is no difference between the VB Rnd and anything else on the market.. <smile>.
As to the Triangular Distribution.. if you think I'm gonna blow the dust off of my old Statistic books.. you got another think coming.. <lol>. Let's see some empirical formulae.. <smile>.
Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
What is the shape of the triangular distribution.? A right triangle with a positive slope? A symetrical triangle with a peak at the midpoint? or?
The way to generate your distribution is to write an equation for Y vs. X. A triangle will have to be in segments. Integerate this and get a funtion of the integral of Y vs X. Normalize the Y values so they sum to 1. Then using the rnd function, generate a number from 0 to 1. Use this as a Y value and determine the related value for X from the equation of the normalized integral of Y vs. X.
A symterical triangular distribution that goes from X1 to X2 with a peak at (X1+X2)/2 (i.e. the midpoint) can be formed by the sum of two uniform distributions that go from X1/2 to X2/2. Each of these can be easily generated from the VB rnd function that gives a uniform distribution from 0 to 1 by multiplying and adding a constant to a variable formed by the rnd function.
I need the values describing the triangle. What are the 3 X values for
the begining of the triangle, the peak, and the end point. I don't need the Y values, since I will assume the triangle area corresponding to the probability must sum to one.
If you provide these I think I can give code to do this. But it will use the VB rnd function somewhere in the code.
After some trial and error, I derived general equations for this. I checked the code by running 10000 variables for various shaoes and did a histogram on them.
Triangular distribution
Note: pdf = probability density function
cdf = cumulative probability
Assume the pdf goes from X1 to X2 with a peak at XP. Then the cdf =
the area under the curve of the pdf.
Let A1 = the area from X1 to Xp
A2 = the area from Xp to X2
A1 + A2 = 1 (sum of all possible probs = 1)
Writing equations for Ax as a function of X and solving for X gives
the following code. z will be a random variable with the desired
triangular distribution.
A1 = (Xp-X1)/(X2-X1) ' area up to peak
A2 = 1-A1 ' area after peak
r = Rnd
If r < = A1 Then
z = X1+Sqr(r*(X2-X1)*(Xp-X1))
Else
z = X2-Sqr((1-r)*(X2-Xp)*(X2-X1))
End If