Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.c 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * core/utils.c
  3. */
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <time.h>
  9. #include <sys/time.h>
  10. extern int verbosity;
  11. /* --------------------------------------------------------------- */
  12. /* maybe not a really goof initialisation... */
  13. int seed_my_rand(int foo)
  14. {
  15. long v1, v2;
  16. v1 = getpid(); v2 = time(NULL);
  17. return v1 ^ v2;
  18. }
  19. /* --------------------------------------------------------------- */
  20. int random1000(int type)
  21. {
  22. int value, foo;
  23. #if DEBUG_LEVEL > 1
  24. fprintf(stderr, ">>> %s(%d)\n", __func__, type);
  25. #endif
  26. switch (type) {
  27. case 0:
  28. value = rand() % 1000;
  29. break;
  30. case 1:
  31. value = (rand()%1000 + rand()%1000) / 2;
  32. break;
  33. case 4:
  34. value = 0;
  35. for (foo=0; foo<4; foo++)
  36. value += rand() % 1000;
  37. value /= 4;
  38. break;
  39. default:
  40. value = -1;
  41. break;
  42. }
  43. return value;
  44. }
  45. /* --------------------------------------------------------------- */
  46. double dtime(void)
  47. {
  48. struct timeval tv;
  49. int foo;
  50. foo = gettimeofday(&tv, NULL);
  51. if (foo) fprintf(stderr, "got %d in %s\n", foo, __func__);
  52. return (double)tv.tv_sec + (double)tv.tv_usec / 1e6;
  53. }
  54. /* --------------------------------------------------------------- */