|
|
Up |
|
|
  |
Author: Arjen MarkusArjen Markus Date: May 22, 2008 02:22
Hello,
I was just checking some information on the random_number and
random_seed
intrinsic subroutines and I came across this text fragment (in the
Compaq Visual
Fortran documentation):
If no argument is specified, a random number based on the date and
time is assigned to the seed.
I wondered if this is standard behaviour, so I wrote the following
program:
program rnd
integer :: seed_size
integer, allocatable, dimension(:) :: seed_data
call random_seed( size = seed_size )
allocate( seed_data(seed_size) )
call random_seed( get = seed_data )
write(*,*) 'Seed size:', seed_size
write(*,*) 'Seed data:', seed_data
|
| Show full article (1.05Kb) |
|
| | 17 Comments |
|
  |
Author: Thomas KoenigThomas Koenig Date: May 22, 2008 03:06
On 2008-05-22, Arjen Markus wrote:
> I came across this text fragment (in the
> Compaq Visual
> Fortran documentation):
>
> If no argument is specified, a random number based on the date and
> time is assigned to the seed.
> I wondered if this is standard behaviour,
It is permitted by the standard, but not required.
[Sample program elided]
> This gives different seed data for g95 and ifort under Linux (that is
> where
> I tested this feature) but not for gfortran - version 4.3.0.
> So my question is: is this a bug in gfortran or is the behaviour of
> random_seed
> described above not standard?
The behavior of gfortran is the result of a design decision with
reproducibility as it goal.
|
| Show full article (0.86Kb) |
|
| | no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: May 22, 2008 03:17
On 22 mei, 12:06, Thomas Koenig wrote:
> On 2008-05-22, Arjen Markus wrote:
>
>> I came across this text fragment (in the
>> Compaq Visual
>> Fortran documentation):
>
>> If no argument is specified, a random number based on the date and
>> time is assigned to the seed.
>> I wondered if this is standard behaviour,
>
> It is permitted by the standard, but not required.
>
> [Sample program elided]
>
>> This gives different seed data for g95 and ifort under Linux (that is
>> where
>> I tested this feature) but not for gfortran - version 4.3.0.
>> So my question is: is this a bug in gfortran or is the behaviour of
>> random_seed ...
|
| Show full article (1.08Kb) |
| no comments |
|
  |
Author: Thomas KoenigThomas Koenig Date: May 22, 2008 03:47
On 2008-05-22, Arjen Markus wrote:
>> If you want different random numbers on each invocation, there's an
>> exmaple in the gfortran documentation (under random_seed).
> The example shown in the documentation is specific to gfortran,
> I guess?
It's standard F95, so it can be used portably (although it may not
be needed with other implementations).
|
| |
| no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: May 22, 2008 04:19
On 22 mei, 12:47, Thomas Koenig wrote:
> On 2008-05-22, Arjen Markus wrote:
>
>>> If you want different random numbers on each invocation, there's an
>>> exmaple in the gfortran documentation (under random_seed).
>> The example shown in the documentation is specific to gfortran,
>> I guess?
>
> It's standard F95, so it can be used portably (although it may not
> be needed with other implementations).
I should have been clearer: I mean the seeding method as documented
is that general too or is it specific to gfortran.
If it is indeed general, that would be nice, but then I wonder
why the size of the seed differs from one compiler to the
next.
Regards,
Arjen
|
| |
| no comments |
|
  |
Author: Dave SeamanDave Seaman Date: May 22, 2008 05:15
On Thu, 22 May 2008 04:19:49 -0700 (PDT), Arjen Markus wrote:
> On 22 mei, 12:47, Thomas Koenig wrote:
>> On 2008-05-22, Arjen Markus wrote:
>>
>>>> If you want different random numbers on each invocation, there's an
>>>> exmaple in the gfortran documentation (under random_seed).
>>> The example shown in the documentation is specific to gfortran,
>>> I guess?
>>
>> It's standard F95, so it can be used portably (although it may not
>> be needed with other implementations).
> I should have been clearer: I mean the seeding method as documented
> is that general too or is it specific to gfortran.
> If it is indeed general, that would be nice, but then I wonder
> why the size of the seed differs from one compiler to the
> next.
> Regards,
> Arjen
He said the seeding method is standard f95, so it can be used portably.
|
| Show full article (1.24Kb) |
| no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: May 22, 2008 05:23
On 22 mei, 14:15, Dave Seaman wrote:
>
> He said the seeding method is standard f95, so it can be used portably.
>
> The size of the seed is implementation dependent, because the length of
> the period of a PRNG is limited by the size of the seed, and therefore it
> would be unwise to constrain implementors in their choice of an
> algorithm.
>
I interpreted it as meaning that the _code_ of the
example is standard Fortran 95, but if the _method_ is
standard as well, then that is very useful indeed.
(I had not seen documentation of the seeding before - I always
assumed that it was left to the implementors of the compiler,
hence the contents of the array used for seeding should be
treated as opaque.)
Regards,
Arjen
|
| |
| no comments |
|
  |
Author: Dave SeamanDave Seaman Date: May 22, 2008 07:46
On Thu, 22 May 2008 05:23:42 -0700 (PDT), Arjen Markus wrote:
> On 22 mei, 14:15, Dave Seaman wrote:
>>
>> He said the seeding method is standard f95, so it can be used portably.
>>
>> The size of the seed is implementation dependent, because the length of
>> the period of a PRNG is limited by the size of the seed, and therefore it
>> would be unwise to constrain implementors in their choice of an
>> algorithm.
>>
> I interpreted it as meaning that the _code_ of the
> example is standard Fortran 95, but if the _method_ is
> standard as well, then that is very useful indeed.
I don't know what you mean by that. The statement
CALL RANDOM_SEED(PUT = seed)
has an implementation-defined meaning. Different processors may treat
the PUT array in different ways, even if the size happens to be the same.
|
| Show full article (1.45Kb) |
| no comments |
|
  |
Author: Thomas KoenigThomas Koenig Date: May 22, 2008 07:54
On 2008-05-22, Arjen Markus wrote:
> I should have been clearer: I mean the seeding method as documented
> is that general too or is it specific to gfortran.
It is standard-conforming (which is why seed is a dynamically
allocated array in this case), and it is very likely to
generate a good seed regardless of the implementation (unless the
PRNG of the implementation is of bad quality, which should hopefully
be rare).
> If it is indeed general, that would be nice, but then I wonder
> why the size of the seed differs from one compiler to the
> next.
In the words of the standard - "Computation of the seed from the
argument PUT is performed in a processor-dependent manner."
Different implementations are free to choose different algorithms.
|
| Show full article (1.33Kb) |
| no comments |
|
  |
|
|
  |
Author: nospamnospam Date: May 22, 2008 09:00
Thomas Koenig wrote:
> On 2008-05-22, Arjen Markus wrote:
>> If no argument is specified, a random number based on the date and
>> time is assigned to the seed.
>
>> I wondered if this is standard behaviour,
>
> It is permitted by the standard, but not required.
It is also an unfortunate example of a result of inadequate attention to
detail in the writing of the standard. The author of those words later
claimed that he had intended to specify whether the processor-dependent
seed was always the same for a given processor, or whether it could vary
like this. Unfortunately, he forgot to actually put this specification
in writing. By the time he explained that this was his intent, the
standard had long been published and there were established
implementations and programs using both different ways.
|
| Show full article (1.92Kb) |
| no comments |
|
|
|
|