相关疑难解决方法(0)

这种随机化的实现在 C 中是如何工作的?

自从我在https://www.tutorialspoint.com/c_standard_library/c_function_rand.htm上找到这个特定的文档以来,我一直在考虑这行特定的代码。srand((unsigned)time(&t));每当我不得不生成一些东西时,我使用它srand(time(NULL))是为了不生成同样的东西,每次我运行程序,但是当我遇到这个来了,我一直在想:是否有任何区别srand((unsigned)time(&t)),并srand(time(NULL))因为对我来说,他们看起来他们做同样的thing.Why是使用的time_t变量,为什么是?地址运算符用于srand()

#include <stdio.h>
#include<stdlib.h>
int main(){
    int i,n;
    time_t t;

    n = 5;

    srand((unsigned)time(&t)); 

    for (i = 0; i < n; i++) {
        printf("%d\n", rand() % 50);
    }
return(0);
}
Run Code Online (Sandbox Code Playgroud)

c srand

0
推荐指数
1
解决办法
174
查看次数

标签 统计

c ×1

srand ×1