aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2016-12-22 03:59:03 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2016-12-22 12:40:48 +0100
commitda73d95bad4736c5e0a6b4b1a811f4dd4525bb4c (patch)
treeef11f50bfdf637a8bb4cc38d393c081683d0983f /libavutil
parent0098eeaa62899136caf61aa76e3be2c198144ecc (diff)
downloadffmpeg-da73d95bad4736c5e0a6b4b1a811f4dd4525bb4c.tar.gz
avutil/random_seed: Improve get_generic_seed() with higher precission clock()
Tested-by: Thomas Turner <thomastdt@googlemail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/random_seed.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c
index 79bc7aff74..179fb23624 100644
--- a/libavutil/random_seed.c
+++ b/libavutil/random_seed.c
@@ -67,6 +67,7 @@ static uint32_t get_generic_seed(void)
uint64_t tmp[120/8];
struct AVSHA *sha = (void*)tmp;
clock_t last_t = 0;
+ clock_t last_td = 0;
static uint64_t i = 0;
static uint32_t buffer[512] = { 0 };
unsigned char digest[20];
@@ -86,11 +87,12 @@ static uint32_t get_generic_seed(void)
for (;;) {
clock_t t = clock();
-
- if (last_t == t) {
- buffer[i & 511]++;
+ if (last_t + 2*last_td + 1 >= t) {
+ last_td = t - last_t;
+ buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (last_td % 3294638521U);
} else {
- buffer[++i & 511] += (t - last_t) % 3294638521U;
+ last_td = t - last_t;
+ buffer[++i & 511] += last_td % 3294638521U;
if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
break;
}