How to use nanosleep for sleeping random amounts of time?
问题 Im trying to use the function nanosleep to make my process sleep for a random amount of time between 1/10th of a second? im using srand() to seed my random number generator, with the process id, that is, im calling: srand(getpid()); then using struct timespec delay; delay.tv_sec = 0; delay.tv_nsec = rand(); nanosleep(&delay, NULL); How can i make sure im sleeping for 0..1/10th of a second? 回答1: I'd say you just need 100000000ULL * rand() / RAND_MAX nanoseconds, this is at most 0.1s and at