From 01684a3784fb5849a1584c8a50eaa5204a146678 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sat, 27 Dec 2014 12:47:40 +0100 Subject: [PATCH] Removes one more rand() use. --- cmdline/nano.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmdline/nano.c b/cmdline/nano.c index bb0be3b6..1fdedae9 100644 --- a/cmdline/nano.c +++ b/cmdline/nano.c @@ -49,9 +49,19 @@ void state_nano(struct snapraid_state* state) pathprint(path, sizeof(path), "%s%s", disk->dir, file->sub); - /* generate a new nanosecond timestamp different than 0 */ + /* set a new nanosecond timestamp different than 0 */ do { - nsec = rand() % 1000000000; + uint32_t nano; + + /* get a random nanosecond value */ + if (randomize(&nano, sizeof(nano)) != 0) { + /* LCOV_EXCL_START */ + fprintf(stderr, "Failed to get random values.\n"); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + + nsec = nano % 1000000000; } while (nsec == 0); /* open it */