简体   繁体   English

如何在C中使用rand()在不带time.h的情况下生成随机数

[英]How to generate random numbers with rand() without time.h in C

如何在C中使用没有time.h的rand()和srand()生成随机数?

You could try givin another seed to the random generator like the program's pid. 您可以尝试给随机生成器提供另一个种子,例如程序的pid。

srand(getpid());
int num = rand();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM