//初始化随机种子 //timeval是个结构体,里边有俩个变量,一个是以秒为单位的,一个是以微妙为单位的
struct timeval now;
gettimeofday(&now, NULL);
unsigned rand_seed = (unsigned)(now.tv_sec*1000 + now.tv_usec/1000); //都转化为毫秒 srand(rand_seed); for (int i=0; i<10; i++) { int _rand = rand()%100; //产生0~99的随机数 //int _rand2 = random()%100; log("%d", _rand); }