[issue27096] Ability to get random bytes from random.Random (as with os.urandom)

2016-05-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: Sorry Campbell, I concur with Serhiy that this isn't worth growing the API. -- resolution: -> rejected status: open -> closed ___ Python tracker ___

[issue27096] Ability to get random bytes from random.Random (as with os.urandom)

2016-05-24 Thread Campbell Barton
Campbell Barton added the comment: @serhiy.storchaka, while a properly working function that uses getrandbits isn't so complex, its not trivial either. It needs to create smaller chunks and join them (also check zero size case which raises an error if passed). eg: ``` def urandom_from_ra

[issue27096] Ability to get random bytes from random.Random (as with os.urandom)

2016-05-23 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- nosy: +tim.peters ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mai

[issue27096] Ability to get random bytes from random.Random (as with os.urandom)

2016-05-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: $ ./python -m timeit -s 'from os import urandom' 'urandom(100)' 10 loops, best of 3: 132 msec per loop $ ./python -m timeit -s 'from random import getrandbits' 'n = 100; getrandbits(n*8).to_bytes(n, "little")' 100 loops, best of 3: 14.1 msec per loop

[issue27096] Ability to get random bytes from random.Random (as with os.urandom)

2016-05-23 Thread Campbell Barton
Campbell Barton added the comment: @r.david.murray, yes, this avoids list creation, but is still quite slow. To create 1mb of data, you can compare the following: python -m timeit -s 'from os import urandom' 'print(len(urandom(100)))' python -m timeit -s 'from random import randint

[issue27096] Ability to get random bytes from random.Random (as with os.urandom)

2016-05-23 Thread R. David Murray
R. David Murray added the comment: It seems reasonable to me, but I'm not the one to sign off on something like this. I've nosied someone who will have an opinion :) Would doing: mybytes = bytes(random.randint(0, 255) for i in range(size)) be faster enough to be workable? I suppose that