如果我想在 C 中生成 0 到 1,000,000 之间的不同随机数,以下内容是否足够?
srand(time(NULL));
int k = (rand() % 1000000;
从我看到的输出来看,只生成了大约 32767 个不同的随机数!
谢谢!
最佳答案
rand int rand (void); Generate random number Returns a pseudo-random integral number in the range between 0 and RAND_MAX.
RAND_MAX Maximum value returned by rand This macro expands to an integral constant expression whose value is the maximum value returned by the rand function.
This value is library-dependent, but is guaranteed to be at least 32767 on any standard library implementation.
关于c - 用 C 生成随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21043042/