2019-01-17 21:51:07 +11:00
|
|
|
/*
|
|
|
|
* core/utils.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
extern int verbosity;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------- */
|
|
|
|
int seed_my_rand(int foo)
|
|
|
|
{
|
|
|
|
long v1, v2;
|
|
|
|
|
|
|
|
v1 = getpid(); v2 = time(NULL);
|
|
|
|
|
|
|
|
return v1 ^ v2;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------- */
|
|
|
|
int random1000(int type)
|
|
|
|
{
|
2019-01-27 23:03:59 +11:00
|
|
|
int value, foo;
|
2019-01-17 21:51:07 +11:00
|
|
|
|
|
|
|
#if DEBUG_LEVEL > 1
|
|
|
|
fprintf(stderr, ">>> %s(%d)\n", __func__, type);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
value = rand() % 1000;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
value = (rand()%1000 + rand()%1000) / 2;
|
|
|
|
break;
|
2019-01-27 23:03:59 +11:00
|
|
|
case 4:
|
|
|
|
value = 0;
|
|
|
|
for (foo=0; foo<4; foo++)
|
|
|
|
value += rand() % 1000;
|
|
|
|
value /= 4;
|
|
|
|
break;
|
2019-01-17 21:51:07 +11:00
|
|
|
default:
|
|
|
|
value = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------- */
|
|
|
|
double dtime(void)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
foo = gettimeofday(&tv, NULL);
|
|
|
|
if (foo) fprintf(stderr, "got %d in %s\n", foo, __func__);
|
|
|
|
|
|
|
|
return (double)tv.tv_sec + (double)tv.tv_usec / 1e6;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------- */
|