python - 顽固分子使用 python 的原始二进制流
问题描述
我正在尝试将 python 数字生成器与 dieharder 结合起来,我发现它可以在 linux 中使用 pipe 来完成
python3 generator.py | dieharder -a -g 200
-g 200
表示我将使用stdin_input_raw
这是顽固者手册中的规范:
Raw binary input reads 32 bit increments of the specified data
stream. stdin_input_raw accepts a pipe from a raw binary stream.
现在我使用随机生成器创建了一些 python 代码:
while True:
sys.stdout.write("{0:b}".format(random.randint(0, 256)))
但我认为它没有按预期工作,因为上面第一次测试的终端命令的结果是:
test_name |ntup| tsamples |psamples| p-value |Assessment
#====================================================================#
diehard_birthdays| 0| 100| 100|0.00000000| FAILED
而对于命令:
cat /dev/urandom | dieharder -a -g 200
这是:
test_name |ntup| tsamples |psamples| p-value |Assessment
#====================================================================#
diehard_birthdays| 0| 100| 100|0.92477826| PASSED
我怀疑我的生成代码raw input stream
不正确,如何在 python 中创建这个流?
解决方案:
while True:
sys.stdout.buffer.write(struct.pack('>I', random.randint(0, 2**32)))
解决方案
推荐阅读
- three.js - 三.js 图像纵横比
- java - 构建失败时,maven-surefire-report-plugin 不生成report.html
- php - 如何将两个不同函数的参数值获取到不同函数中的另一个变量中?
- mysql - 在模式弹出窗口中获取值并更新,而无需在 codeigntier 中刷新页面
- python - Python/Redis 中的任务委托
- c++ - Qt 应用程序有意外的 QDir::currentPath
- java - Springboot:组件类中的java.lang.NullPointerException @autowired
- android - 无法解析符号 getFusedLocationProviderClient 和 LocationCallback
- kotlin - Kotlin:null 和“重载分辨率歧义”
- c# - MVC 5 如何使用表中的 id 创建可点击的行以重新连接到客户编辑?