 # How to do simulation to verify Randomly draw balls into boxes problem?

Suppose we put m balls randomly into n boxes (m>n). Find the expected number of non-empty boxes. Calculate theoretical number, and then use R to validate. The method to calculate by hand is to use indicator function. But how to use R to simulate?

FAQ: Homework Policy

At the core of your solution would probably be the base::sample() function which can randomly sample 'size' number of objects from a set passed in as 'x'

``sample(x=letters[1:26],size=5,replace=TRUE)``

This is the general question "put n balls in m boxes"

It's not the same thing. Your code is get letters from a whole set. My question is put m balls into n boxes.

It's an example of getting a random outcome from a set of possibilities. Like if there are 26 boxes and you distribute 5 balls at random among them.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.