summaryrefslogtreecommitdiff
path: root/intellect-framework-from-internet/starts/meaning-vm/level-2/sugar.cpp
blob: 2a86cca048574c7cfae8e2cae76bc3497bfeb870 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
}

}
}
}