gpt4 book ai didi

c++ - 获得一个字节的随机性

转载 作者:行者123 更新时间:2023-11-28 01:04:58 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What is the most random function in C++?

在 C++ 中,这样安全吗:

int main() {
srand(time(0));
unsigned char arr[10];
for(int i=0; i <sizeof(arr); ++i)
arr[i] = (unsigned char)rand();
}

有没有更好的方法以独立于平台的方式随机填充字节数组?如果失败了,有没有更好的方法在 Windows 上执行此操作? (我知道 rand() 不是一个很好的 PRNG,我只是用它作为例子)。

谢谢!

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