This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Lukasa, Nofar Schnider, glyph, rhettinger, terry.reedy, vstinner
Date 2016-08-17.12:26:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1471436814.16.0.231675631009.issue27706@psf.upfronthosting.co.za>
In-reply-to
Content
"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.
History
Date User Action Args
2016-08-17 12:26:54vstinnersetrecipients: + vstinner, rhettinger, terry.reedy, glyph, Lukasa, Nofar Schnider
2016-08-17 12:26:54vstinnersetmessageid: <1471436814.16.0.231675631009.issue27706@psf.upfronthosting.co.za>
2016-08-17 12:26:54vstinnerlinkissue27706 messages
2016-08-17 12:26:53vstinnercreate