You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Linux's /dev/urandom and Python's os.urandom does not pass #10
import os print( bin(int.from_bytes(os.urandom(1024),'big')))
does not pass Maurer test (09) and approx. Entropy test (12)
print( bin(int.from_bytes(open('/dev/urandom','rb').read(1024),'big'))) does not pass Maurer test (09) and randomly, does not pass approx. Entropy test (12) too
I tried on Python 3.6.9 (default, Jun 29 2022, 11:45:57) [GCC 8.4.0] on linux, using Jetson Nano's Linux
I wonder, does it imply that both incompliance to NIST, or something else
Maurer's Test is only applicable for bit strings of length >= 387840.
As for the approximate entropy test, I think that with enough data (at least 10^6 or something), it might actually pass.
If your bit string is not long enough, the tests might "randomly" fail.
This is expected behaviour — os.urandom(1024) produces only 8,192 bits, well below the 387,840-bit minimum required by Maurer's Universal test. The test was silently returning (-1.0, False) which was confusing. This has been fixed in PR #33: the test now returns a clear error message instead. The Approximate Entropy result with short inputs may also be statistically unreliable — addressed by the minimum-length guards added in PR #34. Closing as addressed.
Activity
phmngcthanh commentedon Nov 26, 2022
I tried on Python 3.6.9 (default, Jun 29 2022, 11:45:57) [GCC 8.4.0] on linux, using Jetson Nano's Linux
I wonder, does it imply that both incompliance to NIST, or something else
ThexXTURBOXx commentedon Jun 28, 2023
Maurer's Test is only applicable for bit strings of length
>= 387840.As for the approximate entropy test, I think that with enough data (at least 10^6 or something), it might actually pass.
If your bit string is not long enough, the tests might "randomly" fail.
For even more reference, see section 4.3: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-22r1a.pdf
fix: replace silent -1.0 return with descriptive error in Universal.py
stevenang commentedon Apr 5, 2026
This is expected behaviour —
os.urandom(1024)produces only 8,192 bits, well below the 387,840-bit minimum required by Maurer's Universal test. The test was silently returning(-1.0, False)which was confusing. This has been fixed in PR #33: the test now returns a clear error message instead. The Approximate Entropy result with short inputs may also be statistically unreliable — addressed by the minimum-length guards added in PR #34. Closing as addressed.