int rand unsigned int min unsigned int max timeval time gettimeofday t

1
2
3
4
5
6
int rand(unsigned int min, unsigned int max) {
timeval time;
gettimeofday(&time, NULL);
srand(((unsigned long long) time.tv_sec * 1000000) + time.tv_usec);
return min > max ? 0 : min + rand() % (max - min);
}