Why isn't the output of RandomChoice a packed array? For instance:
RandomChoice[{.5, .2, .3} -> {1, 2, 3}, 10] Developer`PackedArrayQ @ % {1, 2, 3, 1, 3, 1, 1, 2, 3, 3}
False
In order for RandomChoice to produce a packed array, the RHS of the rule needs to be packed:
pQ = Developer`PackedArrayQ; pack = Developer`ToPackedArray; pQ @ RandomChoice[pack[{.5, .2, .3}] -> pack[{1, 2, 3}], 10] pQ @ RandomChoice[pack[{.5, .2, .3}] -> {1, 2, 3}, 10] pQ @ RandomChoice[{.5, .2, .3} -> pack[{1, 2, 3}], 10] True
False
True
RandomSample as well $\endgroup$