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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. int seed_my_rand(int foo)
  13. {
  14. long v1, v2;
  15. v1 = getpid(); v2 = time(NULL);
  16. return v1 ^ v2;
  17. }
  18. /* --------------------------------------------------------------- */
  19. int random1000(int type)
  20. {
  21. int value;
  22. #if DEBUG_LEVEL > 1
  23. fprintf(stderr, ">>> %s(%d)\n", __func__, type);
  24. #endif
  25. switch (type) {
  26. case 0:
  27. value = rand() % 1000;
  28. break;
  29. case 1:
  30. value = (rand()%1000 + rand()%1000) / 2;
  31. break;
  32. default:
  33. value = -1;
  34. break;
  35. }
  36. return value;
  37. }
  38. /* --------------------------------------------------------------- */
  39. double dtime(void)
  40. {
  41. struct timeval tv;
  42. int foo;
  43. foo = gettimeofday(&tv, NULL);
  44. if (foo) fprintf(stderr, "got %d in %s\n", foo, __func__);
  45. return (double)tv.tv_sec + (double)tv.tv_usec / 1e6;
  46. }
  47. /* --------------------------------------------------------------- */