diff options
Diffstat (limited to 'starts/meaning-vm/level-2/sugar.cpp')
-rw-r--r-- | starts/meaning-vm/level-2/sugar.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/starts/meaning-vm/level-2/sugar.cpp b/starts/meaning-vm/level-2/sugar.cpp new file mode 100644 index 0000000..2a86cca --- /dev/null +++ b/starts/meaning-vm/level-2/sugar.cpp @@ -0,0 +1,32 @@ +#include "sugar.hpp" + +#include <stdlib.h> // int rand(); void srand(int seed); +#include <time.h> // int time(0); int clock_gettime(CLOCK_REALTIME, struct timespec *tp{tv_sec,tv_nsec}) +#include <unistd.h> // usleep(unsigned int usecs) + +namespace intellect { +namespace level2 { +namespace sugar { + +double rand(double min, double max) +{ + // seed random number generator statically, for habit delay + static struct timespec tp; + static int seed = ( + clock_gettime(CLOCK_REALTIME, &tp), + srand(tp.tv_nsec), + tp.tv_nsec + ); + (void)(seed); + + return double(::rand()) / RAND_MAX * (max - min) + min; +} + +void usleep(unsigned int usecs) +{ + ::usleep(usecs); +} + +} +} +} |