From c1be6dbea0f6e2b8d9cb8c422bc2e1cfb41524da Mon Sep 17 00:00:00 2001 From: J08nY Date: Sun, 19 Feb 2017 02:26:27 +0100 Subject: Always read a whole pari_ulong from dev/urandom --- src/math/random.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/math') diff --git a/src/math/random.c b/src/math/random.c index 94197fe..a1d88ab 100644 --- a/src/math/random.c +++ b/src/math/random.c @@ -11,7 +11,11 @@ bool random_init(void) { // Try urandom first FILE *rand = fopen("/dev/urandom", "rb"); if (rand) { - fread(&seed, 1, sizeof(pari_ulong), rand); + size_t read = 0; + while (read < sizeof(pari_ulong)) { + read += fread(&seed + read, 1, sizeof(pari_ulong) - read, rand); + } + fclose(rand); } // Try worse methods later -- cgit v1.3.1