- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am running Monte Carlo simulation and I have to run 1 million replications.
To save time I have to run simulations simultaneously and using "Call Random_seed " to change my random seed and using command "Call random_number()" to generate random numbers.
I have noticed that when I run 20 simulations simultaneously I get some repeated results. This problem is because same random numbers are generated.
How I can resolve this problem?
I am using IVF11 with windows.
I appreciate your help
To save time I have to run simulations simultaneously and using "Call Random_seed " to change my random seed and using command "Call random_number()" to generate random numbers.
I have noticed that when I run 20 simulations simultaneously I get some repeated results. This problem is because same random numbers are generated.
How I can resolve this problem?
I am using IVF11 with windows.
I appreciate your help
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is this parallel all within the same program run once, or in multiple
copies of the program run in parallel? If the same program run once,
just call RANDOM_SEED once. If it is programs run in parallel, you will
need to construct your own seed that differs from run to run. It could use the process ID in combination with the value from SYSTEM_CLOCK to create a seed. The process ID can be obtained by a call to the Windows API routine GetCurrentProcessId (defined in module KERNEL32).
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In about 1986 Scientific American published a column by the Math Guru, whose name I forget, but it required a random number generator to generate genetic code elements. The original code was published in BASIC, and I used MicroSOFT Basic at the time to run the program.It worked a real treat and I enjoyed playing with it on a COMPAQ portable, with two floopy drives and a 100 mm green screen.
I translated the code to Fortran and could never get it to run, because of the exact problem you describe.
If you can inlcude the VB random number generator that might work.
Just a thought
JMN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CALL RANDOM_SEED() with no arguments likely uses the time of day to the nearest second or centisecond or so, and when called back-to-back can return the same seed. You can try to fix this by a call to RANDOM_SEED(SIZE=array_size) to see how big an array it uses, then ALLOCATE(SEED(array_size)) to allocate the default integer array SEED to the correct size and then you can use the sequence:
CALL RANDOM_SEED()
CALL RANDOM_SEED(GET=SEED)
default_integer = QueryPerformanceCounter(lpPerformanceCount)
SEED(1) = lpPerformanceCount
CALL RANDOM_SEED(PUT=SEED)
to first get a seed that is mostly random, but only changes every second or so, then change its first element to a number that changes every clock cycle or so, and put it back in. Not guaranteed to get you a different seed every time, but not as bad as calling RANDOM_SEED() back-to-back without modification.
CALL RANDOM_SEED()
CALL RANDOM_SEED(GET=SEED)
default_integer = QueryPerformanceCounter(lpPerformanceCount)
SEED(1) = lpPerformanceCount
CALL RANDOM_SEED(PUT=SEED)
to first get a seed that is mostly random, but only changes every second or so, then change its first element to a number that changes every clock cycle or so, and put it back in. Not guaranteed to get you a different seed every time, but not as bad as calling RANDOM_SEED() back-to-back without modification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The resolution of the value RANDOM_SEED uses when no arguments are passed seems to be somewhat coarse, in seconds perhaps. But calling RANDOM_SEED in parallel isn't going to help you any. Call it once at the beginning of the program and you should be ok.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is I have to run simulations in parallel.
Let's say I need to generate new random seed 20 time in a second. In the beginning of every replication I am calling Randdom-seed and after it is done for new replication I am calling that again. But all my 20 replications which are running simultaneously are running independently in parallel.
Let's say I need to generate new random seed 20 time in a second. In the beginning of every replication I am calling Randdom-seed and after it is done for new replication I am calling that again. But all my 20 replications which are running simultaneously are running independently in parallel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is this parallel all within the same program run once, or in multiple
copies of the program run in parallel? If the same program run once,
just call RANDOM_SEED once. If it is programs run in parallel, you will
need to construct your own seed that differs from run to run. It could use the process ID in combination with the value from SYSTEM_CLOCK to create a seed. The process ID can be obtained by a call to the Windows API routine GetCurrentProcessId (defined in module KERNEL32).

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