Link to home
Get AccessLog in
Avatar of Jagwarman
Jagwarman

asked on

Random distribution formula

is there a formula that will divide a number randomly between a given number.      
      
So lets say I have 10 clients and 35 widgets.      
      
I want to distribute the widgets across the 10 clients randomly.      
      
so       
      
Client 1      gets 4
Client 2      gets 0
Client 3      gets 3
Client 4      gets 2
Client 5      gets 1
Client 6      gets 1
Client 7      gets 3
Client 8      gets 6
Client 9      gets 8
Client 10      gets 7

Thanks in advance
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try this..
28695867.xlsm
Avatar of Jagwarman
Jagwarman

ASKER

thanks Ryan only this is I was looking for formula rather than vba. The above was an example and so potentially the number of Clients will be a moving target. i.e. I put 10 in example but in live there could be 20 or 70 or 35 or 100 etc.

Regards
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
HI,

Or you could use a UDF returning an array see example

Function RandomWidgets(nrWidgets) As Variant
Dim Res() As Integer
    With Application.Caller
        CallerRows = .Rows.Count
    End With
    ReDim Res(0 To CallerRows - 1)
    Randomize
    For i = 1 To nrWidgets
        rIdx = Rnd * Now() Mod CallerRows
        Res(rIdx) = Res(rIdx) + 1
    Next
    RandomWidgets = Application.Transpose(Res)

End Function

Open in new window

Regards
28695867V1.xlsm
I like that and it's flexible
Fomula driven, for first client, in G4:

=RANDBETWEEN(0,B1)   where B1 has number of widgets

For remaining clients G5 down, against list created manually in column A:

=IF(A6="",$B$1-SUM(G$4:G4),RANDBETWEEN(0,$B$1-SUM(G$4:G4)))

Checks if last client and takes balancing figure other wise takes Random value between remainder and zero.

Thanks
Rob H