3 ms·
"2 / 8 = 0.29" 0.25 according to my calculations pictures and /dev/random should give 0.5, not 0.57, if not they are not properly compressed and it's not a pr
by Aardwolf 7y ago
"2 / 8 = 0.29"
0.25 according to my calculations
pictures and /dev/random should give 0.5, not 0.57, if not they are not properly compressed and it's not a proper random generation, which I don't really believe. Maybe similar error as what happened with the 0.29?
The mean byte value in decimal should be 127.5.
I guess it may be something about the hexadecimal -> decimal -> binary conversion -> count instances of '0' and '1' in string in the python code that is doing something wrong (it's also inefficient to roundtrip through decimal when the original bytes are already binary in the computer and to involve strings in this at all). Does it remove leading zeros perhaps?
- jhoechtl 7y agoWell spoted. And ashaming for the OP
- chmod775 7y agoLooks like he accidentally typed "2 / 7" instead of "2 / 8" in a calculator, then rounded the result?
- MByte 7y agoYes, it's exactly that. The bin function removes leading zeroes.
- jeltz 7y agoThe bug is that bin(decimal)[2:] should be bin(decimal)[2:].rjust(8, '0') or else the leading zeros are not counted. Personally I would probably have used shift for a simple script like this.
- joezydeco 7y agoOr a 255-entry precomputed lookup table.