[issue7889] random produces different output on different architectures
Terrence Cole
report at bugs.python.org
Wed Feb 10 08:53:19 CET 2010
Terrence Cole <terrence at zettabytestorage.com> added the comment:
Thank you for all the help! I'm glad to see that the use of hash() on buffer compatible objects is an actual gotcha and not just me being obtuse.
Also, for those googling who, like me, won't be able to use 3.2's from_bytes until 3.2 is released in December, here is code to convert a bytes to an int:
>>> n = 0
>>> off = 0
>>> data = b'\xfc\x00'
>>> for c in data[::-1]:
... n += c << off
... off += 8
...
>>> print(n)
64512
Or, if you prefer the functional style:
>>> sum([c<<off for c,off in zip(data[::-1],range(0,len(data)*8+1,8))])
64512
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7889>
_______________________________________
More information about the Python-bugs-list
mailing list