gpt4 book ai didi

windows - 命令提示随机数是如何生成的?

转载 作者:可可西里 更新时间:2023-11-01 13:54:31 30 4
gpt4 key购买 nike

在命令提示符环境中,有一个变量%random%,它使用某种算法生成伪随机数。

有人知道生成这些数字的算法吗?

最佳答案

%random% 动态变量生成一个从 0 到 32,767(含)的随机数。生成这些数字的算法是这样的:

srand((unsigned)time(NULL));

It turns out that the Windows command processor uses the standard naïve algorithm for seeding the random number generator (Quote from here)

由于时间种子,它每秒吐出一个新数字。

正如 dbenham 所指出的,由于伪随机性和将时间作为种子,在同一秒内打开的两个命令提示符将输出完全相同的数字。

关于windows - 命令提示随机数是如何生成的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37427787/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com