Improved coin.py

This commit is contained in:
Luke Rogers 2012-09-06 16:52:32 +12:00
parent 72b7c3ed2d
commit 75b07b2584

View file

@ -1,17 +1,5 @@
# Created by Lukeroge, improved by TheNoodle
from util import hook
from random import getrandbits
# yay for wtfcode
def flip_simple(count):
heads, tails = 0, 0
for x in xrange(count):
if not getrandbits(1):
heads += 1
else:
tails += 1
return heads, tails
from random import getrandbits, normalvariate
@hook.command(autohelp=False)
@ -23,17 +11,17 @@ def coin(inp, me=None):
else:
amount = 1
if amount > 9001:
return "Too many coins! Maximum is 9001."
if amount > 90001:
return "Too many coins! Maximum is 90001."
elif amount == 1:
flip = getrandbits(1)
if flip == 1:
if getrandbits(1):
me("flips a coin and gets heads.")
else:
me("flips a coin and gets tails.")
elif amount == 0:
me("makes a coin flipping motion with its hands.")
else:
flips = flip_simple(amount)
heads = int(normalvariate(.5 * amount, (.75 * amount) ** .5))
tails = amount - heads
me("flips %i coins and gets " \
"%i heads and %i tails." % (amount, flips[0], flips[1]))
"%i heads and %i tails." % (amount, heads, tails))