Re: [PATCH 2/2] kconfig: improve seed in randconfig

From: Geert Uytterhoeven
Date: Sun Mar 15 2009 - 06:53:34 EST


On Sun, Mar 15, 2009 at 11:28, Sam Ravnborg <sam@xxxxxxxxxxxx> wrote:
> 'make randconfig' uses glibc's rand function, and the seed of
> that PRNG is set via:
>
> Â Â Â Â Â Â Â Â Â Â Â Âsrand(time(NULL));
>
> But 'time()' only increases once every second - freezing the
> randconfig result within a single second.
>
> My Nehalem testbox does randconfig much faster than 1 second
> Âand i have a few scripts that do 'randconfig until condition X'
> loops.
>
> Those scripts currently waste a lot of CPU time due to randconfig
> changing its seed only once per second currently.
>
> Change the seed to be micrseconds based. (I checked the statistical
> spread of the seed - the now.tv_sec*now.tv_usec multiplication
> there further improves it.)

> + Â Â Â Â Â Â Â Â Â Â Â gettimeofday(&now, NULL);
> +
> + Â Â Â Â Â Â Â Â Â Â Â seed = (unsigned int)(now.tv_sec*now.tv_usec);

Just wondering: may there be some platforms that don't offer microsecond
resolution, and tv_usec is always zero?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/