Re: Random Numbers



In article <e8194j$jql$1@xxxxxxxxxxxxxxxxx>,
pa@xxxxxxxxxxxxxxxxxxxxx (Pierre Asselin) writes:
Steven G. Kargl <kargl@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

[ wants random numbers reproducible from run to run ]
OTOH, I do use code of the form

call random_seed(size=n)
allocate(put(n))
put = nrand + 37 * (/ (i - 1, i = 1, n) /) ! nrand is user input.
call random_seed(put=put)
deallocate(put)

Does the standard specify what you can or cannot pass to
random_seed(put=) ? I mean the content, not just the size. I was
bitten once by an implementation that was very picky about the
contents of its seed vectors. I did as you show, asking random_seed()
for the size and filling the array with some sequence salted by a
small user input. The resulting sequence was anything but random !

IIRC the standard promises that you can call random_seed(get=) and
use the result in a random_seed(put=), but as far as I know you
can't construct your own seed.

PUT (optional)
shall be a default integer array of rank one and size N. It is an
INTENT (IN) argument. It is used in a processor-dependent manner
to compute the seed value accessed by the pseudorandom number
generator.

You can construct your own seed. It seems that you may have
run into a quality of implementation problem with the compiler
that you used. Were any of PUT(1:N) equal to zero. I recall that
the old UNIX rand() function had a major problem with a seed
of 0.

--
Steve
http://troutmask.apl.washington.edu/~kargl/
.



Relevant Pages

  • Re: Employer looking 4 online C++ aptitude tests; recommendations?
    ... Undefined behaviour ... >OTOH, this is clearly a better test than the commercial ones I've seen. ... bool is defined by the standard to be "an integral type". ... Does the standard specify what the integral value of "true" should be? ...
    (comp.lang.cpp)
  • Re: Random Numbers
    ... Steven G. Kargl wrote: ... OTOH, I do use code of the form ... Does the standard specify what you can or cannot pass to ... contents of its seed vectors. ...
    (comp.lang.fortran)