Function tata(x, n%, mi%, ma%)
Dim i, sDat(), s%, tmp1%, tmp2%
'-----------------------------------------------------
Application.Volatile 'Supprimer cette ligne si on ne
'veut pas de recalcul automatique.
'-----------------------------------------------------
ReDim sDat(0, 0 To n - 1)
If x >= mi * n And ma * n >= x And n Then
Randomize
For i = n - 1 To 1 Step -1
tmp1 = WorksheetFunction.Min(ma, x - s - mi * i)
tmp2 = WorksheetFunction.Max(mi, x - s - ma * i)
sDat(0, i) = tmp2 + Int((tmp1 - tmp2 + 1) * Rnd)
s = s + sDat(0, i)
Next
sDat(0, 0) = x - s
Else
For i = 0 To n - 1
sDat(0, i) = "-"
Next
End If
tata = sDat
End Function