Message272928
"Right now the way to work around this is to get some deterministic hash from your string; one mechanism being a truncated SHA256 hash, ..."
It looks like I missed something. Lib/random.py already computes the SHA-512 hash of you pass a string to random.Random constructor?
Using a string as a seed for random.Random already works as expected in Python 3.6:
haypo@selma$ python3 -c "import random; r=random.Random('abc'); print(''.join(map(str, (r.randrange(10) for x in range(10)))), hash('abc'))"
8755240310 6396067846301608395
haypo@selma$ python3 -c "import random; r=random.Random('abc'); print(''.join(map(str, (r.randrange(10) for x in range(10)))), hash('abc'))"
8755240310 -1771227904188177035
haypo@selma$ python3 -c "import random; r=random.Random('abc'); print(''.join(map(str, (r.randrange(10) for x in range(10)))), hash('abc'))"
8755240310 1726464324144904308
haypo@selma$ python3 -c "import random; r=random.Random('abc'); print(''.join(map(str, (r.randrange(10) for x in range(10)))), hash('abc'))"
8755240310 2069899884777593571
haypo@selma$ python3 -c "import random; r=random.Random('abc'); print(''.join(map(str, (r.randrange(10) for x in range(10)))), hash('abc'))"
8755240310 -8244933646981095152
haypo@selma$ python3 -c "import random; r=random.Random('abc'); print(''.join(map(str, (r.randrange(10) for x in range(10)))), hash('abc'))"
8755240310 -3269879388324739111
It was already the case in Python 2.7. |
|
Date |
User |
Action |
Args |
2016-08-17 12:26:54 | vstinner | set | recipients:
+ vstinner, rhettinger, terry.reedy, glyph, Lukasa, Nofar Schnider |
2016-08-17 12:26:54 | vstinner | set | messageid: <1471436814.16.0.231675631009.issue27706@psf.upfronthosting.co.za> |
2016-08-17 12:26:54 | vstinner | link | issue27706 messages |
2016-08-17 12:26:53 | vstinner | create | |
|