Given a number of boxes, randomly distribute n balls into these boxes.

rtoboxes(n, boxes, weights = NULL, capacities = NULL)

Arguments

n

A natural number. The number of balls to put into the boxes.

boxes

A natural number. The number of boxes.

weights

A non-negative numeric vector. The relative probabilities of putting a ball in each box. Default is each box is equally likely.

capacities

A vector of natural numbers. The capacity of each box. Default is each box has infinite capacity.

Value

A vector of natural numbers with the same length as boxes. The number of balls placed in each box.

See also

rfromboxes

Examples

rtoboxes(30, 7)
#> [1] 5 4 4 6 4 3 4
rtoboxes(30, 7, capacities = c(rep(1, 3), rep(7, 4)))
#> [1] 1 1 1 7 7 6 7
rtoboxes(30, 7,
  capacities = c(rep(1, 3), rep(70, 4)),
  weights = c(rep(0.1, 6), 1)
)
#> [1]  1  1  1  2  4  2 19