# Bus.py, illustration of the bus paradox

import random,sys

rnd = random.Random(12345)

def doexpt(opt):
   arvtm = 0.0
   nbus = 0
   while arvtm < opt:
      nbus += 1
      arvtm += rnd.expovariate(0.1)
   return arvtm-opt

def main():
   observationpoint = float(sys.argv[1])
   nreps = int(sys.argv[2])
   sum = 0.0
   for i in range(nreps):
      wait = doexpt(observationpoint)
      sum += wait
   print 'the estimated mean wait is', sum/nreps

if __name__ == '__main__': main()
