Randomize three variables subject to sum always equal to 1
Sorry, no: Both of your programs lead to an average value
of 0.5 for the first variable, I think.
I suggest:
Public Function TRAT() As Variant
Dim vTemp As Variant
Dim i1, i2, i3 As Integer
Application.Volatile
ReDim vTemp(0 To 2)
i1 = Int(Rnd * 3)
i2 = (i1 + 1) Mod 3
i3 = (i1 + 2) Mod 3
vTemp(i1) = Round(Rnd, 15)
vTemp(i2) = Round(Rnd * (1 - vTemp(i1)), 15)
vTemp(i3) = 1 - vTemp(i1) - vTemp(i2)
TRAT = Application.Transpose(vTemp)
End Function
Kind regards,
sulprobil
|