From: CTallant on
Hello! Let me start this off by saying I am very new to Fortran. I
started learning it about a week and a half ago.

I have a program that has character strings (quotes) in an array, and
upon starting the program, the idea was that a random number generator
would then be used to produce a number within my array boundaries, and
that number would be used to specify the quote pulled up. I want the
quotes to vary each time you start the program. I was looking at random
seed, but I would rather that the user doesn't need to interact with
the program to vary the seed and get a new quote. Is there a different
method to accomplish this goal without user input? Like I said, I'm new
to this, so the simpler the solution, the more likely I am to
understand it. :)

Program Friendly
Implicit None
Character(LEN=50),Dimension(1:1500)::quotes
Real::x,lBound=1,uBound=1500
Integer::y

....I assign the quotes to the array here...

Call random_number(x)
x=(x*(uBound-lBound))+lBound
y=x
Print*, quotes(y)

End Program Friendly

Thank you!

Cat

From: dpb on

CTallant(a)afit.edu wrote:
> Hello! Let me start this off by saying I am very new to Fortran. I
> started learning it about a week and a half ago.
>
> I have a program that has character strings (quotes) in an array, and
> upon starting the program, the idea was that a random number generator
> would then be used to produce a number within my array boundaries, and
> that number would be used to specify the quote pulled up. I want the
> quotes to vary each time you start the program. I was looking at random
> seed, but I would rather that the user doesn't need to interact with
> the program to vary the seed and get a new quote. Is there a different
> method to accomplish this goal without user input? Like I said, I'm new
> to this, so the simpler the solution, the more likely I am to
> understand it. :)
.....

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

From: Richard E Maine on
dpb <dpbozarth(a)swko.net> 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.

The two most popular methods of assuring that you get a new seed eith
each run are:

1. Set the starting seed yourself based on date/time. See the
date_and_time and random_seed intrinsics in any text. It isn't hard to
throw together something using those two intrinsics, and for the
described purpose, you aren't likely to be too picky about the
statistical properties.

2. Save the seed to a file somewhere. Initialize the seed from the file
when you start (with a default action in case the file doesn't exist).
Save the latest seed to the file when you terminate (or after you are
otherwise done with it for a run). This does require access to the file,
which might be an issue if multiple people are running the program.

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
From: dpb on

Richard E Maine wrote:
> dpb <dpbozarth(a)swko.net> 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. ...

....snip rest of explanation of what Standard says and some history...

OK, good to know. I checked w/ the CVF LRF rather than the Standard.
D/CVF documentation is usually pretty reliable on noting what is an
extension or is nonstandard but apparently not in this particular
instance...

From: Steven G. Kargl on
In article <1hhoqyq.14h27aclvhckcN%nospam(a)see.signature>,
nospam(a)see.signature (Richard E Maine) writes:
> dpb <dpbozarth(a)swko.net> 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/