This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, libgfortran] Always seed the PRNG from the OS


Hi,

now that I have changed the PRNG algorithm behind RANDOM_NUMBER, and
thus breaking compatibility (in the weak sense that the stream of
random numbers will be different), one might also do a few other minor
improvements.

The attached patch makes sure to always initialize the PRNG seed from
the OS (/dev/urandom or falling back to gettimeofday ^ getpid) so that
the random generator state is different every time one runs a program.
This is probably closer to what people intuitively expect, and if one
wants a constant seed, it's easy enough to do by explicitly calling
RANDOM_SEED.

Unless there are objections, I intend to commit this in a few days. Regtested on
x86_64-pc-linux-gnu.

libgfortran:

2016-08-16  Janne Blomqvist  <jb@gcc.gnu.org>

    * intrinsics/random.c (master_init): New variable.
    (init_rand_state): Move below getosrandom (), maybe initialize
    master_state.
    (random_seed_i4): If called with no arguments, set master_init to
    false, and reinitialize. If called with PUT=, set master_init to
    true.
    (random_seed_i8): Likewise.

testsuite:

2016-08-16  Janne Blomqvist  <jb@gcc.gnu.org>

    * gfortran.dg/random_4.f90: Initialize seed before using, handle
    the last special seed value.
    * gfortran.dg/random_7.f90: Use size for last array member instead
    of hardcoded value.


-- 
Janne Blomqvist

Attachment: random-init.diff
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]