- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
the variation in the data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page