7.8. Probability Distributions and Drive Thrus#
7.8.1. Introduction#
Introduction
In this section, we show how random numbers are used to simulate a fast-food restaurant with a drive-thru order window as illustrated in the animation below.
For an explanation of how to create this animation, see the “Introduction to Python” section in the Python Programming Guide

For Discussion
Suppose you are the owner of a fast-food restaurant. Currently, there is one drive-thru lane, but you are considering adding a second drive-thru lane. What factors need to be considered in deciding whether to add a second drive-thru lane?
A statistical simulation model uses data of customer arrival and ordering times to re-create a scenario and explore options such as adding a second drive-thru lane. (For example, see the video
“Fast Food Drive Thru 2 lanes versus 1” YouTube, uploaded by Daniel Hickman, 5 March 2013, https://www.youtube.com/watch?v=M9v6bx3l4Dk. Permissions: YouTube Terms of Service
Calculus is used in statistically-based simulations since probabilities are represented as areas under curves called probability distributions.
Here we will focus on the use of uniform (constant) and exponential distributions to model arrival times of customers.
7.8.2. Distributions#
A computer simulation of 1 versus 2 drive-thru lanes uses probabilities computed using definite integrals. The probability that some timed event
Example 1 Suppose the time to place an order is given by a uniform distribution
Solution: probability=
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
f= lambda t:0*t+1/100
x=np.linspace(20,120,200)
y=f(x)
plt.figure(figsize=(7,3))
plt.plot(x,y)
plt.xlim((0,125))
plt.ylim((0,.015))
plt.bar(25,1/100,10,alpha=0.1,align='edge',color='k',edgecolor='k')
plt.title('Uniform Distribution U(20,120)')
plt.text(1,.005,'Shaded area between t=25 and t=35 equals 1/10')
plt.text(16,.01,'y=1/100',color='b')
plt.xlabel('Order Time t (seconds)')
Text(0.5, 0, 'Order Time t (seconds)')

Example 2a) An exponential distribution has the form
Solution. probability =
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
f= lambda t: np.exp(-t)
x=np.linspace(0,5,100)
y=f(x)
plt.figure(figsize=(3,3))
plt.plot(x,y)
x1=np.linspace(0,3,10)
y1=f(x1)
plt.fill_between(x1,y1,color='lightgray')
plt.title('Exponential Distribution E(1)=e^(-t)')
plt.text(-.2,0,'Shaded area = .95')
plt.text(1,.6,'y=e^(-t)',color='b')
plt.xlabel('Time t to next arrival (seconds)')
Text(0.5, 0, 'Time t to next arrival (seconds)')

Example 2b) Find the value of
Solution
Example 3a) Using the value of
Solution
Example 3b) Use your function in part a) to find the probability that the next car will arrive within 2 minutes.
Solution
7.8.3. Use of Random Numbers#
We will explain how a value
A=length of time before the next car arrives at the parking lot
O=length of time to place an order
P=length of time to pay for the food
F=length of time to pick up food
A=Length of time before next arrival#
Let
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,5,100)
f= np.exp(-x) #standard (unit) normal distribution
plt.figure(figsize=(8, 4))
plt.plot(x,f,color='k',label="Probability Density Function f(x)")
plt.xlim((0,5))
plt.ylim((0,1))
plt.xlabel("t")
plt.grid()
plt.legend()
plt.show()

The corresponding cumulative distribution function (cdf) is
Here is a graph of this cdf:
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0,5,100)
F= 1-np.exp(-t) #standard (unit) normal distribution
plt.figure(figsize=(8, 4))
plt.plot(t,F,color='k',label="Cumulative Distribution F(t)")
plt.xlim((0,5))
plt.ylim((0,1))
plt.xlabel("A=time to next arrival (in minutes)")
plt.grid()
plt.legend()
plt.show()
Note that the
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0,5,100)
F= 1-np.exp(-t) #standard (unit) normal distribution
plt.figure(figsize=(8, 4))
plt.plot(t,F,color='k',label="Cumulative Distribution F(t)")
plt.xlim((0,5))
plt.ylim((0,1))
plt.text(-.15,.7,"r",color='r',size=15)
plt.text(-np.log(1-.7)-.07,-.05,"A=-ln(1-r)",color='r',size=15)
plt.plot([0,-np.log(.3),-np.log(.3)],[.7,.7,0],color='r')
plt.xlabel("A=time to next arrival (in minutes)")
plt.grid()
plt.legend()
plt.show()
O=length of time to place an order#
Let
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,50,1000)
f= (1/30)*(np.heaviside(x-15,0)-np.heaviside(x-45,0)) #standard (unit) normal distribution
plt.figure(figsize=(8, 4))
plt.plot(x,f,color='k',label="Probability Density Function f(x)")
plt.xlim((0,50))
plt.ylim((0,.05))
plt.xlabel("x")
plt.grid()
plt.legend()
plt.show()

Then, the cumulative distribution function (cdf) is
Here is a graph of this cdf:
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(15,45,100)
F= ((t-15)/30)*np.heaviside(t-15,0) #U(30,15)
plt.figure(figsize=(8, 4))
plt.plot(t,F,color='k',label="Cumulative Distribution F(t)")
plt.xlim((15,45))
plt.ylim((0,1))
plt.xlabel("O=time to place order (in seconds)")
plt.grid()
plt.legend()
plt.show()

As before, the
As such, each random number
Show code cell source
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(15,45,100)
F= ((t-15)/30)*np.heaviside(t-15,0) # U(30,15)
plt.figure(figsize=(8, 4))
plt.plot(t,F,color='k',label="Cumulative Distribution F(t)")
plt.xlim((15,45))
plt.ylim((0,1))
plt.text(15-.5,.7,"r",color='r',size=15)
plt.text(15+30*.7,-.05,"O=15+30r",color='r',size=15)
plt.plot([15,15+30*.7,15+30*.7],[.7,.7,0],color='r')
plt.xlabel("O=time to place order (in seconds)")
plt.grid()
plt.legend()
plt.show()

7.8.4. Exercises#
Exercises
An important probability function called the exponential distribution has the form
The exponential distribution is used to describe the amount of time until some event occurs such as the time to the next arrival of a car at a drive-thru window. More specifically, the probability that the next car arrives somewhere between
a) Suppose
b) Using
c) Find the value of
d) Using your answer to part c), find a function
e) Use your answer to d) to find the probability that the next car will arrive within 3 minutes.
Let
length of time to pay for an order of food.
a) Let
b) Let
Let
be the length of time to pick up food. Let be a random variable giving the length of time (in seconds) to pick up an order. We assume is uniformly distributed on the interval [30,90] (denoted U(30,90). Show how to use a pseudo-random number to generate a value for