Improved coin.py
This commit is contained in:
parent
72b7c3ed2d
commit
75b07b2584
1 changed files with 7 additions and 19 deletions
|
@ -1,17 +1,5 @@
|
||||||
# Created by Lukeroge, improved by TheNoodle
|
|
||||||
from util import hook
|
from util import hook
|
||||||
from random import getrandbits
|
from random import getrandbits, normalvariate
|
||||||
|
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
@hook.command(autohelp=False)
|
@hook.command(autohelp=False)
|
||||||
|
@ -23,17 +11,17 @@ def coin(inp, me=None):
|
||||||
else:
|
else:
|
||||||
amount = 1
|
amount = 1
|
||||||
|
|
||||||
if amount > 9001:
|
if amount > 90001:
|
||||||
return "Too many coins! Maximum is 9001."
|
return "Too many coins! Maximum is 90001."
|
||||||
elif amount == 1:
|
elif amount == 1:
|
||||||
flip = getrandbits(1)
|
if getrandbits(1):
|
||||||
if flip == 1:
|
|
||||||
me("flips a coin and gets heads.")
|
me("flips a coin and gets heads.")
|
||||||
else:
|
else:
|
||||||
me("flips a coin and gets tails.")
|
me("flips a coin and gets tails.")
|
||||||
elif amount == 0:
|
elif amount == 0:
|
||||||
me("makes a coin flipping motion with its hands.")
|
me("makes a coin flipping motion with its hands.")
|
||||||
else:
|
else:
|
||||||
flips = flip_simple(amount)
|
heads = int(normalvariate(.5 * amount, (.75 * amount) ** .5))
|
||||||
|
tails = amount - heads
|
||||||
me("flips %i coins and gets " \
|
me("flips %i coins and gets " \
|
||||||
"%i heads and %i tails." % (amount, flips[0], flips[1]))
|
"%i heads and %i tails." % (amount, heads, tails))
|
||||||
|
|
Reference in a new issue