X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Frandom_seed.c;h=d1c9a3f7046d7efada2e11194819e113ab0f6bb7;hb=65d7d46f717c1d5731a172772c0f16a4b272ab32;hp=d1ded7b50960c6ede82b65b291be0c790b979556;hpb=6fb07c7d85c0d0464e5bdaaad55cc2b774468b3d;p=ffmpeg diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c index d1ded7b5096..d1c9a3f7046 100644 --- a/libavutil/random_seed.c +++ b/libavutil/random_seed.c @@ -64,9 +64,11 @@ static int read_random(uint32_t *dst, const char *file) static uint32_t get_generic_seed(void) { - uint8_t tmp[120]; + uint64_t tmp[120/8]; struct AVSHA *sha = (void*)tmp; clock_t last_t = 0; + clock_t last_td = 0; + clock_t init_t = 0; static uint64_t i = 0; static uint32_t buffer[512] = { 0 }; unsigned char digest[20]; @@ -86,15 +88,19 @@ 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 + (CLOCKS_PER_SEC > 1000) >= 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; - if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8) - break; + last_td = t - last_t; + buffer[++i & 511] += last_td % 3294638521U; + if ((t - init_t) >= CLOCKS_PER_SEC>>5) + if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8) + break; } last_t = t; + if (!init_t) + init_t = t; } if(TEST) {