[Python-checkins] cpython (merge 3.6 -> default): merge
raymond.hettinger
python-checkins at python.org
Mon Nov 21 17:13:34 EST 2016
https://hg.python.org/cpython/rev/018c2e0f82c3
changeset: 105301:018c2e0f82c3
parent: 105299:8e59aff28e2a
parent: 105300:c508baa300bb
user: Raymond Hettinger <python at rcn.com>
date: Mon Nov 21 14:13:29 2016 -0800
summary:
merge
files:
Doc/library/random.rst | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -426,25 +426,32 @@
Simulation of arrival times and service deliveries in a single server queue::
- from random import gauss, expovariate
+ from random import expovariate, gauss
+ from statistics import mean, median, stdev
average_arrival_interval = 5.6
average_service_time = 5.0
stdev_service_time = 0.5
num_waiting = 0
+ arrivals = []
+ starts = []
arrival = service_end = 0.0
for i in range(20000):
if arrival <= service_end:
num_waiting += 1
arrival += expovariate(1.0 / average_arrival_interval)
- print(f'{arrival:6.1f} arrived')
+ arrivals.append(arrival)
else:
num_waiting -= 1
service_start = service_end if num_waiting else arrival
service_time = gauss(average_service_time, stdev_service_time)
service_end = service_start + service_time
- print(f'\t\t{service_start:.1f} to {service_end:.1f} serviced')
+ starts.append(service_start)
+
+ waits = [start - arrival for arrival, start in zip(arrivals, starts)]
+ print(f'Mean wait: {mean(waits):.1f}. Stdev wait: {stdev(waits):.1f}.')
+ print(f'Median wait: {median(waits):.1f}. Max wait: {max(waits):.1f}.')
.. seealso::
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list