From eed690240a8c718b9c54520eb363a8e577dca786 Mon Sep 17 00:00:00 2001 From: Jean-Pierre PRUNARET Date: Thu, 19 Jan 2017 23:10:25 +0100 Subject: [PATCH] extraction dans un repo distant --- rand/Makefile | 12 --------- rand/main.c | 68 --------------------------------------------------- 2 files changed, 80 deletions(-) delete mode 100644 rand/Makefile delete mode 100644 rand/main.c diff --git a/rand/Makefile b/rand/Makefile deleted file mode 100644 index a303bfa..0000000 --- a/rand/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -BIN:=random -OUT?=path_if_not_defined - -all: build - -build: $(BIN) - cp -v $(BIN) $(OUT)/ - -install: $(BIN) - -$(BIN): main.c - gcc main.c -Wall -lm -o $@ diff --git a/rand/main.c b/rand/main.c deleted file mode 100644 index 83ac801..0000000 --- a/rand/main.c +++ /dev/null @@ -1,68 +0,0 @@ -#define _POSIX_C_SOURCE 200809L - -#include -#include -#include -#include -#include - -/** - * Return a random number between 0 and limit inclusive. - * - */ -int rand_lim(int limit) { - - int divisor = RAND_MAX/(limit+1); - int retval; - - do { - retval = rand() / divisor; - } while (retval > limit); - - return retval; -} - -void print_current_time_with_ms (void) { - long ms; // Milliseconds - time_t s; // Seconds - struct timespec spec; - - clock_gettime(CLOCK_REALTIME, &spec); - - s = spec.tv_sec; - ms = round(spec.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds - - printf ( "Current time: %ld.%03ld seconds since the Epoch\n" - , (intmax_t)s - , ms - ); -} - -long int get_current_time_ms_part (void) { - long milliseconds; - time_t seconds; - struct timespec spec; - - clock_gettime(CLOCK_REALTIME, &spec); - - seconds = spec.tv_sec; - milliseconds = round(spec.tv_nsec / 1.0e6); // Convert nanoseconds to milliseconds - return spec.tv_nsec; -} - -int main(int argc, char **argv) { - /** - * time precision is 1 second. 2+ calls in same second return same value - */ - //srand(time(NULL)); - srand(get_current_time_ms_part()); - - int random_value = rand_lim(1); - - //printf("value: %d\n", random_value); - printf("%d", random_value); - - //return rand_lim(1); - return random_value; -}; -