Here’s what I need to do:
I need to simulate a server, which sends alarms at random intervals, i.e. after 2 secs, then after 4, after 10 but always within some sort of range.
What is the best way to achieve this?
Here’s my fist idea:
1.) Choose a random value between 0 and 10.
2.) Sleep for that amount of time
3.) Send an alarm to the client
4.) Repeat forever (i.e. while (true))
Your idea doesn’t sound so bad. Of course, you could go a more sophisticated path using timers and signals, but it depends on the requirements and using simply sleep() is maybe the fastest and easiest way for your purposes. Go for it 🙂