deal or no deal
Bengt Richter
bokr at oz.net
Thu Dec 22 10:42:09 EST 2005
On Thu, 22 Dec 2005 09:29:49 -0500, rbt <rbt at athop1.ath.vt.edu> wrote:
>The house almost always wins or are my assumptions wrong...
>
>import random
>
>amounts = [.01, 1, 5, 10, 25, 50, 75, 100, 200, 300, 400, 500, 750,
> 1000, 5000, 10000, 25000, 50000, 75000, 100000, 200000,
> 300000, 400000, 500000, 750000, 1000000]
>
>results = []
>
>count = 0
>while count < 10:
> count = count + 1
> pick = random.choice(amounts)
> if pick < 100000:
> results.append("NBC won... Your briefcase contains $%s" %pick)
> else:
> results.append("You won... Your briefcase contains $%s" %pick)
>
>results.sort()
>print "Here are 10 random picks: "
>for result in results:
> print result
I don't know what you are doing, but 10 is a small sample to draw confident
conclusions from. E.g., try counting how many times pick<100000 out of
a larger number, e.g.,
(BTW, the expression x<y has the value True or False, and True and False are
int subclass instances with int values 1 and 0 respectively, so the sum below
is adding 1 whenever random.choice(amounts)<100000 and 0 otherwise)
>>> import random
>>> amounts = [.01, 1, 5, 10, 25, 50, 75, 100, 200, 300, 400, 500, 750,
... 1000, 5000, 10000, 25000, 50000, 75000, 100000, 200000,
... 300000, 400000, 500000, 750000, 1000000]
>>> sum(random.choice(amounts)<100000 for _ in xrange(1000))
736
>>> sum(random.choice(amounts)<100000 for _ in xrange(1000))
734
>>> sum(random.choice(amounts)<100000 for _ in xrange(1000))
730
>>> sum(random.choice(amounts)<100000 for _ in xrange(1000))
721
>>> sum(random.choice(amounts)<100000 for _ in xrange(1000))
753
What should the sum be?
>>> amounts.index(100000)
19
is the number of numbers < 100000 in amounts
>>> len(amounts)
26
is the total number of numbers
So if you choose with uniform probability, you'd expect
>>> 19./26
0.73076923076923073
to be the fraction satisfying pick<100000
With a larger sample, the fraction should show better, e.g.,
>>> sum(random.choice(amounts)<100000 for _ in xrange(1000000))
730983
Does that help?
Regards,
Bengt Richter
More information about the Python-list
mailing list