Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

random_seed

38 views
Skip to first unread message

glen herrmannsfeldt

unread,
Jul 18, 2007, 5:41:54 PM7/18/07
to
I was trying out random_seed in gfortran, which with SIZE=K returns 8.

I then tried passing the values array, conveniently dimensioned 8, from
date_and_time to random_seed. It seems, though, that the random_seed of
gfortran ignores the 7th and 8th elements.

http://linux-decnet.sourceforge.net/faq-4.html#ss4.2

seems to indicate that it might only use the first four.

As far as I know, this is completely legal, but still, it would be
nice if it only used four elements to report that for SIZE=K.

Other seed routines that I know of that use large seeds also
supply a routine to seed with a single default integer.

It would be nice to have a convenient way to take the result from
DATA_AND_TIME and make a good seed out of it.

integer dt(8)
call date_and_time(values=dt)
i=0
call random_seed(size=k)
print *,'k=',k
print *,dt
if(k>8) stop 'oops, k>8'
dt(1)=dt(8)
call random_seed(put=dt(1:k))
do
i=i+1
f=100
call random_number(rand)
test=1370*rand
if(test<=f) exit
enddo
print *,test,i
end

-- glen

Thomas Koenig

unread,
Jul 18, 2007, 5:31:19 PM7/18/07
to
On 2007-07-18, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:
> I was trying out random_seed in gfortran, which with SIZE=K returns 8.

This is actually system-dependent. If the system supports
kind=16 reals, size= returns 12.

[...]

> http://linux-decnet.sourceforge.net/faq-4.html#ss4.2

This URL is about DECNET :-)

[random_seed]

> seems to indicate that it might only use the first four.

Not quite. To quote from libgfortran/intrinsic/random.c:

/* We use three KISS random number generators, with different
seeds.
As a matter of Quality of Implementation, the random numbers
we generate for different REAL kinds, starting from the same
seed, are always the same up to the precision of these types.
We do this by using three generators with different seeds, the
first one always for the most significant bits, the second one
for bits 33..64 (if present in the REAL kind), and the third one
(called twice) for REAL(16).
*/

The fifth and following seed values are only used when
generating random numbers with more precision than default
real.

> Other seed routines that I know of that use large seeds also
> supply a routine to seed with a single default integer.

Those are often multiplicative congruent algorithms, which
generally generate inferior quality random numbers.

> It would be nice to have a convenient way to take the result from
> DATA_AND_TIME and make a good seed out of it.

Hmm... I can see the problem. The most significant digits come from
the first four values, which don't vary very fast in this case :-)

Well, this is something that can be addressed. I have filed
PR 32812 about this.

glen herrmannsfeldt

unread,
Jul 18, 2007, 6:57:25 PM7/18/07
to
Thomas Koenig wrote:

(snip, I wrote)

>>http://linux-decnet.sourceforge.net/faq-4.html#ss4.2

> This URL is about DECNET :-)

Oops...

(snip)

>>Other seed routines that I know of that use large seeds also
>>supply a routine to seed with a single default integer.

> Those are often multiplicative congruent algorithms, which
> generally generate inferior quality random numbers.

I didn't explain it well. The ones I meant have large
sees, maybe even thousands of bits and supply a way to load
and store the whole seed. In addition, they supply a routine
to set the large seed given one default (likely 32 bit) integer.

How it generates the large seed from that 32 bit integer is
implementation dependent, but hopefully it is done in a way
that generates good random numbers. That reduces the
probability of users generating a poor large seed from a
small seed value such as the time of day.

-- glen


0 new messages