【问题标题】:Why are the random numbers all the same with MSYS2?为什么MSYS2的随机数都一样?
【发布时间】:2020-11-21 21:35:06
【问题描述】:

我正在尝试使用std::random_device 生成随机数,但每次运行程序时它们都是相同的。我使用在线 IDE 尝试了相同的代码,它按预期运行。根据answer here,这是 Cygwin 和 MSYS2 中的错误。

如何升级 MSYS2? 我尝试在其终端中运行命令 pacman -Syupacman -Su,但出现错误:

MSYS ~ $ pacman -Syuu error: mingw32: key
"4A6129F4E4B84AE46ED7F635628F528CF3053E04" is unknown error: key
"4A6129F4E4B84AE46ED7F635628F528CF3053E04" could not be looked up
remotely error: mingw64: key
"4A6129F4E4B84AE46ED7F635628F528CF3053E04" is unknown error: key
"4A6129F4E4B84AE46ED7F635628F528CF3053E04" could not be looked up
remotely error: msys: key "4A6129F4E4B84AE46ED7F635628F528CF3053E04"
is unknown error: key "4A6129F4E4B84AE46ED7F635628F528CF3053E04" could
not be looked up remotely :: Synchronizing package databases... 
mingw32                  472.5 KiB   305K/s 00:02
[#####################] 100%  mingw32.sig              438.0   B 
0.00B/s 00:00 [#####################] 100% error: mingw32: key "4A6129F4E4B84AE46ED7F635628F528CF3053E04" is unknown error: key
"4A6129F4E4B84AE46ED7F635628F528CF3053E04" could not be looked up
remotely error: failed to update mingw32 (invalid or corrupted
database (PGP signature))  mingw64                  475.0 KiB   346K/s
00:01 [#####################] 100%  mingw64.sig              438.0   B
0.00B/s 00:00 [#####################] 100% error: mingw64: key "4A6129F4E4B84AE46ED7F635628F528CF3053E04" is unknown error: key
"4A6129F4E4B84AE46ED7F635628F528CF3053E04" could not be looked up
remotely error: failed to update mingw64 (invalid or corrupted
database (PGP signature))  msys                     189.8 KiB   164K/s
00:01 [#####################] 100%  msys.sig                 438.0   B
0.00B/s 00:00 [#####################] 100% error: msys: key "4A6129F4E4B84AE46ED7F635628F528CF3053E04" is unknown error: key
"4A6129F4E4B84AE46ED7F635628F528CF3053E04" could not be looked up
remotely error: failed to update msys (invalid or corrupted database
(PGP signature)) error: failed to synchronize all databases

在 Windows 上生成随机数是否有任何替代方案或解决方法?

【问题讨论】:

  • 你在播种你的 RNG 吗?
  • @Andy 这不是随机设备的作用吗?据我了解,问题在于它在 msys2 中没有正确实现(但我不敢相信没有人可以在 Windows 上生成随机数)。
  • 嗯,是的——不知道它是如何工作的。而且你可以在 Windows 上生成随机数......但它们是仅限 Windows 的 API(如 CryptGenRandom())——当然 Windows 有 PRNG,如(srandrand),但谁想处理种子呢?更多的。 ETA:我的错误 CryptGenRandom 也是 PRNG...并且已弃用!
  • 您使用的是哪个版本的 GCC?与链接问题中的相同吗?您可能需要重新安装 MSYS 和 MinGW 以获得最新版本。 4.8 版现在非常旧了,还没有完整的 C++11 实现。
  • @Someprogrammerdude g++(Rev3,由 MSYS2 项目构建)9.1.0

标签: c++ windows random cygwin msys2


【解决方案1】:

我通过引用 this news page on MSYS2 让它工作。我必须先运行pacman -Sydd pacman,然后才能执行其余步骤。

【讨论】:

    猜你喜欢
    • 2013-11-21
    • 2021-12-19
    • 1970-01-01
    • 2013-06-07
    • 2014-01-05
    • 2019-01-01
    • 2018-11-07
    • 2010-09-06
    相关资源
    最近更新 更多