View Single Post
  #4   Report Post  
Jim Cone
 
Posts: n/a
Default

Daniel,

See if this comes close...
'---------------------------------
Sub FindNumbersThatAverage()
' Provides random numbers that average a predetermined amount.
' Jim Cone - San Francisco, USA - May 29, 2005
Dim lngN As Long
Dim lngLow As Long
Dim lngTemp As Long
Dim lngHigh As Long
Dim lngTarget As Long
Dim lngQuantity As Long
Dim lngArray() As Long

'Establish parameters...
lngLow = 50
lngHigh = 100
lngTarget = 80
lngQuantity = 10

'Sanity check
If lngLow lngTarget Or lngHigh < lngTarget Then
Exit Sub
End If

'The number of numbers must be an even number <g
If Not lngQuantity Mod 2 = 0 Then
lngQuantity = lngQuantity + 1
End If

ReDim lngArray(1 To lngQuantity)

For lngN = 1 To lngQuantity Step 2
'Get random values between the high and low parameters.
Randomize lngTemp
lngTemp = Int(Rnd * (lngHigh - lngLow + 1)) + lngLow

'Assign random values
lngArray(lngN) = lngTemp
lngArray(lngN + 1) = 2 * lngTarget - lngTemp

'If the high/low range is not centered on the target average
'then the random results may need adjusting.
If lngArray(lngN + 1) lngHigh Then
lngArray(lngN) = 2 * lngTarget - lngHigh + lngN
lngArray(lngN + 1) = lngHigh - lngN
End If
If lngArray(lngN + 1) < lngLow Then
lngArray(lngN) = 2 * lngTarget - lngLow - lngN
lngArray(lngN + 1) = lngLow + lngN
End If
Next 'lngN

'Stick it on the worksheet.
Range("A1", Cells(1, lngQuantity)).Value = lngArray()
End Sub
---------------------------------



"Daniel Lugones" <Daniel wrote in message
...
I have a number, lets say 80. I want to find other values, lets say 10 number
values, between 50 and 100 such as that those numbers added have an average
of 80.
In other words:
a + b + c + d + e + f + g +... = 80
How can I find random values between 50 and 100 (a, b, c, d, etc) whose
average is 80.
Is it possible in Excel 2000?
thank you.
Daniel Lugones