public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libfortran/52879] New: Pathological reseeding of PRNG generator genernates poor sequence
@ 2012-04-05 15:51 kargl at gcc dot gnu.org
  2014-01-07 11:35 ` [Bug libfortran/52879] " dominiq at lps dot ens.fr
  2014-02-09  1:43 ` kargl at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: kargl at gcc dot gnu.org @ 2012-04-05 15:51 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52879

             Bug #: 52879
           Summary: Pathological reseeding of PRNG generator genernates
                    poor sequence
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libfortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kargl@gcc.gnu.org


It is possible to reseed the gfortran's PRNG with sets of
seeds that generate poor sequences of random numbers.  This
problem can to light from the discussion in 

https://groups.google.com/group/comp.lang.fortran/browse_frm/thread/660c46a52644a8ad?hl=en#


Consider the program 

program foo

   implicit none

   character(len=40), parameter :: fmt = '(A,12(I0,1X),A,F10.8)'
   integer i, seed_size, date(8)
   integer, allocatable :: new_seed(:)
   real x

   call random_seed(size=seed_size)

   allocate(new_seed(1:seed_size))

   do i = 6, 12, 2
      call date_and_time(values=date)
      new_seed = 1
      new_seed(1) = i * (sum(date(1:3)) + sum(date(5:8)))
      call random_seed(put=new_seed)
      call random_number(x)
      write(*,fmt) 'seeds = [', new_seed, '], x = ', x
      call sleep(i)
   end do
   print *
   do i = 6, 12, 2
      call date_and_time(values=date)
      new_seed = 1
      new_seed(12) = i * (sum(date(1:3)) + sum(date(5:8)))
      call random_seed(put=new_seed)
      call random_number(x)
      write(*,fmt) 'seeds = [ ', new_seed, '], x = ', x
      call sleep(i)
   end do

   deallocate(new_seed)

end program foo

With 4.6, 4.7, and trunk, I get


troutmask:sgk[239] gfc46 -o bar bar.f90 && ./bar
seeds = [15852 1 1 1 1 1 1 1 1 1 1 1 ], x = 0.76322097
seeds = [21200 1 1 1 1 1 1 1 1 1 1 1 ], x = 0.76322097
seeds = [26590 1 1 1 1 1 1 1 1 1 1 1 ], x = 0.76322097
seeds = [31332 1 1 1 1 1 1 1 1 1 1 1 ], x = 0.76322097

seeds = [ 1 1 1 1 1 1 1 1 1 1 1 15744 ], x = 0.76526332
seeds = [ 1 1 1 1 1 1 1 1 1 1 1 21048 ], x = 0.76410544
seeds = [ 1 1 1 1 1 1 1 1 1 1 1 26400 ], x = 0.76371950
seeds = [ 1 1 1 1 1 1 1 1 1 1 1 31812 ], x = 0.76429844

It would seem plausible to an ordinary user that if a
single seed value is changed, the generated sequence 
will (significantly?) change.  In the first case above,
the sequences are identical while in the second case
there appears to be a correlation among the low (high)
order bits of the initially generated values.

random_seed currently scrambles/unscrambles user
specified seeds to hopefully prevent a bad set of
seed values.  One possible fix would be to XOR the
user specified seeds with the default seeds before
doing the scrambling.  On output, the seeds would
be unscrambled and then again XOR'd with the 
default seeds.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libfortran/52879] Pathological reseeding of PRNG generator genernates poor sequence
  2012-04-05 15:51 [Bug libfortran/52879] New: Pathological reseeding of PRNG generator genernates poor sequence kargl at gcc dot gnu.org
@ 2014-01-07 11:35 ` dominiq at lps dot ens.fr
  2014-02-09  1:43 ` kargl at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: dominiq at lps dot ens.fr @ 2014-01-07 11:35 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52879

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-01-07
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Still present at r206385. AFAICT [ x 1 1 1 1 1 1 1 1 1 1 1 ] is next
[ x 1 1 1 0 7864504 0 4587601 2097191 3145761 6029545 13238442 ] and
[ 1 1 1 1 1 1 1 1 1 1 1 x ] [ 1 1 1 1 0 7864504 0 4587601 2097191 3145761
6095041 y ].


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug libfortran/52879] Pathological reseeding of PRNG generator genernates poor sequence
  2012-04-05 15:51 [Bug libfortran/52879] New: Pathological reseeding of PRNG generator genernates poor sequence kargl at gcc dot gnu.org
  2014-01-07 11:35 ` [Bug libfortran/52879] " dominiq at lps dot ens.fr
@ 2014-02-09  1:43 ` kargl at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: kargl at gcc dot gnu.org @ 2014-02-09  1:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52879

--- Comment #2 from kargl at gcc dot gnu.org ---
Potential patch 

http://gcc.gnu.org/ml/fortran/2014-02/msg00047.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-02-09  1:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-05 15:51 [Bug libfortran/52879] New: Pathological reseeding of PRNG generator genernates poor sequence kargl at gcc dot gnu.org
2014-01-07 11:35 ` [Bug libfortran/52879] " dominiq at lps dot ens.fr
2014-02-09  1:43 ` kargl at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).