From c866a1b74fe7bb5fa6fc422ebf4006b3df7e5067 Mon Sep 17 00:00:00 2001 From: moneromooo Date: Sat, 31 Jan 2015 13:01:03 +0000 Subject: [PATCH] dice: fix the tiniest bias Max value from the hash is 0xffffffff, not 0x100000000 --- tipbot/modules/dice.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tipbot/modules/dice.py b/tipbot/modules/dice.py index 1039146..636da0f 100644 --- a/tipbot/modules/dice.py +++ b/tipbot/modules/dice.py @@ -39,7 +39,7 @@ def Roll(link): try: s = GetServerSeed(link,'dice') + ":" + GetPlayerSeed(link,'dice') + ":" + str(rolls) sh = hashlib.sha256(s).hexdigest() - roll = float(long(sh[0:8],base=16))/0x100000000 + roll = float(long(sh[0:8],base=16))/0xffffffff return rolls, roll except Exception,e: log_error('Failed to roll for %s: %s' % (identity,str(e))) @@ -203,7 +203,7 @@ def Fair(link,cmd): link.send_private("for future rolls. Then follow these steps:") link.send_private("Calculate the SHA-256 sum of serverseed:playerseed:rollnumber") link.send_private("Take the first 8 characters of this sum to make an hexadecimal") - link.send_private("number, and divide it by 0x100000000. You will end up with a number") + link.send_private("number, and divide it by 0xffffffff. You will end up with a number") link.send_private("between 0 and 1 which was your roll for that particular bet") link.send_private("See !faircode for Python code implementing this check") @@ -215,7 +215,7 @@ def FairCode(link,cmd): link.send_private("import sys,hashlib,random") link.send_private("try:") link.send_private(" s=hashlib.sha256(sys.argv[1]+':'+sys.argv[2]+':'+sys.argv[3]).hexdigest()") - link.send_private(" roll = float(long(s[0:8],base=16))/0x100000000") + link.send_private(" roll = float(long(s[0:8],base=16))/0xffffffff") link.send_private(" print '%.16g' % roll") link.send_private("except:") link.send_private(" print 'need serverseed, playerseed, and roll number'")