Specify the parameters: low, high, average and set size.
Set size is limited to the number of cells in a row, however, with
minor modifications the set size could be increased to the number
of cells in a column.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)
Sub MakeNumbers()
Call FindNumbersThatAverage(dblLow:=200, dblHigh:=800, dblTarget:=400, lngSetSize:=100)
End Sub
Function FindNumbersThatAverage(ByRef dblLow As Double, ByRef dblHigh As Double, _
ByRef dblTarget As Double, ByRef lngSetSize As Long)
' Provides random numbers that average a predetermined amount.
' May 29, 2005 - Jim Cone - San Francisco, USA
' Sept 27, 2007 - Radically revised by Jim Cone.
Dim j As Long
Dim lngN As Long
Dim lngTemp As Long
Dim lngArray() As Long
Dim dblAdjust As Double
ReDim lngArray(1 To lngSetSize)
'Sanity check
If dblLow > dblTarget Or dblHigh < dblTarget Then Exit Function
'If target value is not centered between high and low values then this
'allocates the random values proportionally.
dblAdjust = (dblHigh - dblTarget) / (dblHigh - dblLow)
Randomize
For lngN = 1 To (dblAdjust * lngSetSize)
'Get random values between the target and low parameter.
lngTemp = Int(Rnd * (dblTarget - dblLow) + dblLow)
'Place random values in the array
lngArray(lngN) = lngTemp
Next 'lngN
Randomize
For lngN = (dblAdjust * lngSetSize + 1) To lngSetSize
'Get random values between the target and high parameter.
lngTemp = Int(Rnd * (dblHigh - dblTarget) + dblTarget)
'Place random values in the array
lngArray(lngN) = lngTemp
Next 'lngN
'Do a random sort on the array values.
Randomize
For lngN = lngSetSize To 1 Step -1
j = Int(Rnd * lngN + 1)
lngTemp = lngArray(lngN)
lngArray(lngN) = lngArray(j)
lngArray(j) = lngTemp
Next 'lngN
'Stick it on the worksheet (in a single row).
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Resize(1, lngSetSize).Value = lngArray()
End Function
'------------------
"rcc"
<
[email protected]>
wrote in message
Thanks, Mike. I'm not sure if that would work in my case since I don't
actually have a data set to create a cumulative distribution from in the
first place. Really the only information I have is the upper and lower
bounds and the mean. It's from those values that I want to create a
distribution that looks similar to a normal distribution.
One idea that I had is to sort of combine two normal curves together. I
would have a piecewise function that described a normal distribution. On one
side of the mean, the function would be described by one standard deviation
and on the other side of the mean, another standard deviation. Is that too
much a hack to be theoretically sound?