Re: [hackers] [sbase][PATCH] libutil/random: better random seed

From: Steve Ward <planet36_AT_gmail.com>
Date: Mon, 4 Mar 2024 19:08:38 -0500

On Mon, Mar 4, 2024 at 5:03 PM Elie Le Vaillant <eolien55_AT_disroot.org> wrote:
>
> Thanks NRK
> ---
> libutil/random.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/libutil/random.c b/libutil/random.c
> index 780ba29..6b795a9 100644
> --- a/libutil/random.c
> +++ b/libutil/random.c
> _AT_@ -1,4 +1,5 @@
> #include <stdint.h>
> +#include <stdio.h>
> #include <time.h>
>
> static uint64_t globalstate;
> _AT_@ -66,7 +67,7 @@ rng32_seed_r(uint64_t *state)
> {
> struct timespec ts;
> clock_gettime(CLOCK_REALTIME, &ts);
> - *state = ts.tv_nsec;
> + *state = (intptr_t)&printf ^ time(NULL) ^ (ts.tv_nsec * 0xAC5533CD);
> }
>
> void
> --
> 2.44.0
>
>

Instead of calling time(NULL), you already have the second of the
epoch in ts.tv_sec.
Received on Tue Mar 05 2024 - 01:08:38 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 06 2024 - 08:12:38 CET