This function that performs random apportionment works
Apal[v_, s_] :=
Module[{vv = v, ss = s},
p = vv/Total[vv]; (*probability to draw an object*)
r = Range[Length[vv]]; (* nomber og groups *)
rc = RandomChoice[p -> r, ss];(* give an object to a group at each draw *)
Counts[rc] (* count of the number of objects *)
ns = r /. Counts[rc]
(* extraction in increasing order of the number of object for each group *)
]
as shown by
Apal[{12, 34, 13, 53, 67, 86, 44}, 128]
and
Total[Apal[{12, 34, 13, 53, 67, 86, 44}, 128]
which gives always 128.
But it prints some warnings
Set::write: Tag Times in <|5->26,6->32,4->26,2->17,7->16,1->6,3->5|> {6,18,31,38,58} is Protected.
I wonder where is my mistake and if there are no how to turn off the warnings.
OfforQuiet. For exampleOff[Set::write]will turn off allSet::writemessages, wich would be a very bad idea, though. – JEM_Mosig Jul 10 '17 at 21:44Counts[rc]should be removed. The value it returns is never used. – m_goldberg Jul 10 '17 at 21:47