**Objective**:
To
develop a procedure for randomly allocating chocolate chips to cookies
using a probability experiment employing the Monte Carlo technique. (For
a general description of the Monte Carlo technique go to the
Elementary
Probability Demo Collection.)
**Level: **High
school or precalculus, or probability courses for math majors.

**Prerequisites:
**Basic
probability concepts; knowledge of equally likely chance and the chance
of winning a lottery.

**Platform: **A
calculator or computer which has a function that
generates random numbers. There is an accompanying **JAVA
applet** which performs simulations discussed in this demo:
javacookiesimulation.

**Instructor's
Notes:**
This demo is an __allocation simulation__ that
uses the Monte Carlo technique. That is, we have a certain resource that
is to be distributed in a random manner. We want to approximate the probability
of certain outcomes. Here we consider randomly distributing chocolate chips
to cookies.

A cookie manufacturer bakes a batch of 100 cookies
and decides to randomly allocate **N** > 0 chocolate chips to the batch.
For advertising and quality control, the manufacturer wants to estimate
the (average) number of cookies in a batch that will have no chocolate
chips.

A way to simulate the allocation of the chocolate
chips to the cookies is to imagine that the batch of 100 cookies is arranged
in a table consisting of 10 rows and 10 columns. Using this __model__
for the batch, each cookie can be located by its row-column position. We
generate pairs of random numbers (x, y) where both x and y are integer
values from 1 to 10. Each time a particular (x, y) pair is generated we
add 1 to the table entry at that location.

After the **N **chips have been allocated, we
count the number of cookies with no chips. This provides an estimate of
the average number of cookies containing no chips in a batch of 100 cookies
to which **N** chips are allocated. Figure 1 shows one such allocation
where the red zeros indicate the cookies with no chips. In this simulation
we used **N = 150**. There were 20 cookies with no chips and the largest
number of chips allocated to one cookie is 4.

**
Figure 1.**
By repeating the procedure a large number
of times keeping **N** fixed at 150 we can obtain a good estimate of
the average number of cookies with no chips for a batch of 100 cookies.
The MATLAB routine chipsim.ZIP (click to download)
implements the strategy outlined above. (Figure 1 and the animation below
were obtained from this routine.) We have also developed a
**JAVA applet** for this demo which has the
same functionality :
javacookiesimulation.
(The displays of the applet may vary slightly because of the browser you use
and the screen resolution of your monitor.) We repeated the simulation 10 times using
a batch of 100 cookies with an allocation of **N **= 150 chips. The
results are displayed in the following table.

The average number of cookies with no chips from this
set of 10 experiments is 22.4. We stress that this is only an estimate
of the average number of cookies contain no chips when **N** = 150 chips
are randomly allocated to the 100 cookies. A larger set of experiments
may be required to accurately estimate the "on average" number of cookies
with no chips for arbitrary choices of the number of chips **N**.
The animation below shows a typical simulation
of the random allocation process for **N** = 150.

This simulation can be modified in a variety
of ways. The MATLAB routine chipsim (cited above) lets the user specify
the number of chips **N** to allocate to the 100 cookies. Selecting
a different number of chips to allocate will change the estimates of the
number of the 100 cookies that, on average, contain no chips. Another way
to modify the simulation is to change the number of cookies in a batch.
In general, simulations of this type provide an estimate of the probability
of selecting a cookie with no chips from a batch of **C** cookies to
which **N** chips have been randomly allocated. The __estimate__
is computed by the ratio

In Table 1 we summarize a set of experiments for various
choices of **N**, the number of chips to be allocated to **C** =
100 cookies. For each value of **N** 10 experiments were performed and
the indicated averages computed.
**Table 1.**

The averages for a set of experiments you perform like
those reported in Table1 will vary somewhat. In order to obtained very
accurate estimates of theoretical probabilities involved quite a large
number of experiments should be performed. To see details of the experiments
summarized in Table 1 click on dataset.
In advanced courses, theoretical
techniques can be used to compute the such probabilities. For example,
the following table gives the theoretical probabilities as indicated for
a batch of 100 cookies randomly allocated **N = 150** chips.

**Credits**:
This demo was adapted from

W.E. Haigh, "Using Microcomputers
to Solve Probability Problems", *Mathematics Teacher*, v78,
No.2, 1985, pp124-126
and portions are reprinted with permission
from Mathematics Teacher, copyright 1985 by the National Council of Teachers
of Mathematics. All rights reserved.

We also appreciate the cooperation of
Professor W.E.
Haigh

Department of Mathematics

Northern State University

in its development.
We also acknowledge contributions by Un
Jung Sin , student at Temple University. The MATLAB routine chipsim was
written by David R. Hill. The Java applet was developed by Philip Nicastro
and David Spearing, both students at Temple University.