Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

random_seed,random_number

Intel_C_Intel
Employee
457 Views
I wrote a Monte Carlo computer simulation programme using Intel Fortran Compiler 5.0. In it I need to generate random values. So, I put call random_seed() in the beginning of my programme and used call random_number(x) further. To my great surprise I always get the same sequence of "random" values. Same thing in Linux with Intel Compiler. All the other Fortran Compilers (Compaq Visual Fortran, Microsoft) I have, work fine. Am I doing something wrong or should I write to support?????? Please help.

0 Kudos
3 Replies
Steven_L_Intel1
Employee
457 Views
What you're doing "wrong" is assuming that a call to RANDOM_SEED with no arguments initializes the seed to something that will be different each time you run the program. The standard does not require this. As you have found, some implementations do, some don't.

You can set the seed(s) yourself based on values returned from SYSTEM_CLOCK or DATE_AND_TIME. Make sure that you inquire first to see how big the seed array is and then be sure to fill in all the values.

Steve
0 Kudos
isn-removed200637
457 Views
IMHO, this behaviour is useful, as you can test your program knowing that you will get exactly the same sequence of pseudorandom numbers each time, so that you can be sure that any changes you observe in the results are due to your own programming activity and not due to
the variation in the data.
0 Kudos
gregscvf
Beginner
457 Views
In balab's defense, I don't get it either. The Help states:
If no argument is specified, a random number based on the date and time is assigned to the seed.

It further reads in the example:
CALL RANDOM_SEED ! Processor initializes the seed randomly from the date and time

To me this means it should have a different seed at different times when no argument is used. If I wanted the same seed, I would use the Put argument.

Greg
0 Kudos
Reply