Re: Random Numbers





CTallant@xxxxxxxx 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. :)

This is complete irrelevant to your question. But as a
of good style (in my opinion), you'd ne better of to
declare your arrays ar

integer, parameter :: lbound = 1, ubound = 1500
Character(LEN=50),Dimension(lbound:ubound)::quotes
real :: x

That way, you only specify the numbers once. Sure as
there are green apples, sometime in the future you, or
somebody else, will modify your original version and
forget to make the changes in both places.

There's no problem with

x=(x*(uBound-lBound))+lBound

and having lbound and ubound be integers. Fortran
does the conversion to real autromatically for the
multiply and add.

Incidently, there's no problem doing
Y =(x*(uBound-lBound))+lBound
the conversion to integer will also happen automatically.

*** Hendrickson

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


.


Quantcast