- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
링크가 복사됨
3 응답
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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