Re: Random Numbers



In article <1hhoqyq.14h27aclvhckcN%nospam@xxxxxxxxxxxxx>,
nospam@xxxxxxxxxxxxx (Richard E Maine) writes:
dpb <dpbozarth@xxxxxxxx> wrote:

Calling RANDOM_SEED w/o any arguments resets the seed based on the
current CPU date and time.

That is *NOT* guaranteed by the standard. The standard just says that it
assigns a processor-dependent seed. There is no requirement or even
implication that it is based on the data and time. I think that might
have been the intent of the original author of that part of the
standard; I think I recall him once saying so. But unfortunately, he
didn't manage to write it down that way or even communicate that to the
rest of the committee. By the time he noticed that the written words
didn't say what he intended, it was way too late because multiple
implementations had followed what was actually written in the standard.
There's a lesson somewhere in here about technical writing. Some (maybe
even most; I don't have all the data handy) compilers do it that way. I
regard that as desireable behavior, but it is not guaranteed. You could
well find that it is set to the same starting seed each time, which
isn't at all what you want.

I know of one compiler that initializes the PRNG with a specific set
of seeds when RANDOM_SEED is called without any arguments.

program d
real x(5)
call random_seed()
call random_number(x)
print '(5F8.3)', x
call sleep(10) ! Nonstandard intrinsic to burn time
call random_seed()
call random_number(x)
print '(5F8.3)', x
end program d

troutmask:kargl[208] ./z
0.126 0.083 0.330 0.402 0.248
0.126 0.083 0.330 0.402 0.248

I may be in the minority, but I prefer this behavior because
it allows one to get the same sequence of random numbers
without fussing with the seeds. This is quite useful while
developing a Monte Carlo simulation. 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)

to provide different sequences once my Monte Carlo development
is finished.

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



Relevant Pages

  • Re: R6RS Ratified
    ... farmers who are now prohibited from saving their seeds. ... wondering why a more formal procedure, which makes it clear who owns ... that this would make it difficult to maintain and evolve the standard? ...
    (comp.lang.scheme)
  • Re: Hotel32 @ Monaco
    ... Monte Carlo. ... Yeah, they sent me an email, too. ... $250 a night, MIDWEEK, for a standard 2 queen room! ...
    (alt.vacation.las-vegas)