Sum of 15 random +/- integers always greater than or equal to
Peter:
Thanks for your taking the time to come up with an answer.
It works great!
Mike
"Peter T" wrote:
Typo -
Generate a column of 15 random integers from -99,999 to +99,999
change
Const cMinMaX As Long = 999999 * 2
to
Const cMinMaX As Long = 99999 * 2
Peter T
"Peter T" <peter_t@discussions wrote in message
...
Hi Mike,
If (?) this is right there's is a very small possibility the Do loop could
run many times
Sub test()
Dim i As Long, n As Long
Dim nArr(1 To 15, 1 To 1) As Long ' 2D to dump to cells maybe
Dim nTmpSum As Long, nSum As Long
Const cMinMaX As Long = 999999 * 2
Dim testCounter As Long
Do
For i = 1 To 15
nArr(i, 1) = cMinMaX * (Rnd() - 0.5)
nTmpSum = nTmpSum + nArr(i, 1)
Next
nSum = nTmpSum
nTmpSum = 0
testCounter = testCounter + 1
Loop Until nSum = 0
Debug.Print nSum, testCounter & " Do-loop(s)"
'Range("A1:A15").Value = nArr
End Sub
Regards,
Peter T
"MikeM" <michael[dot]mittelmanl[at]db[dot]com wrote in message
...
Howdy:
What I'd like to do is the following:
Generate a column of 15 random integers from -99,999 to +99,999
The sum of these 15 random integers must be greater than or equal to
zero.
Thanks.
Mike
|