-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
44 lines (34 loc) · 798 Bytes
/
common.h
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
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef TIME_H
#define TIME_H
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#define TIME_ST() clock_t __tm_st__ = clock ();
#define TIME_ED() clock_t __tm_ed__ = clock ();
#define TIME_VAL() ((double)(__tm_ed__ - __tm_st__) / CLOCKS_PER_SEC)
static void rand_init (void);
static char *rand_string (size_t len);
static long rand_long (long from, long to);
static inline void
rand_init (void)
{
srand ((unsigned)time (NULL));
}
static inline long
rand_long (long from, long to)
{
assert (from < to);
return rand () % (to - from) + from;
}
static inline char *
rand_string (size_t len)
{
char *ret;
if (!(ret = (char *)malloc (len + 1)))
return NULL;
for (size_t i = 0; i < len; i++)
ret[i] = (char)rand_long (32, 127);
ret[len] = 0;
return ret;
}
#endif