- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
one argument of RANDOM_SEED( ) is size, which is stimulated as follows.
"must be scalar and of type integer. Set to the number of integers (N) that the processor uses to hold the value of the seed."
I tried the example folowed and found N is always equal to 2. If this is the case, why not just make it clear using 2 instead of N? Another argument put is required to be an integer array of rank one and size greater than or equal to N. I don't see the case where N is not equal to 2.
Thanks for your time.
"must be scalar and of type integer. Set to the number of integers (N) that the processor uses to hold the value of the seed."
I tried the example folowed and found N is always equal to 2. If this is the case, why not just make it clear using 2 instead of N? Another argument put is required to be an integer array of rank one and size greater than or equal to N. I don't see the case where N is not equal to 2.
Thanks for your time.
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Because the number is implementation-dependent. For portable code, you must ask for the value of N and then allocate your seed array to that size. We might decide to change the size in the future if we use a different algorithm. Other compiler vendors make their own choice of algorithm which may have different seed sizes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The follows are an example from the manual. The results are also pasted. Would you explain a little bit? Why does gseed get different results?
program mainResults:
implicit none
integer::isize,seed(2),gseed(2),hiseed(2),zseed(2)
real ran_harvest(10)
data seed /123456789,987654321/
data hiseed /-1,-1/
data zseed /0,0/
open(unit=10,file='random.txt')
call random_seed(size=isize)
write(10,*)"size",isize
call random_seed(put=hiseed(1:isize))
call random_seed(get=gseed(1:isize))
write(10,*),'hiseed gseed',hiseed,gseed
call random_seed(put=zseed(1:isize))
call random_seed(get=gseed(1:isize))
write(10,*),'zseed gseed',zseed,gseed
call random_seed(put=seed(1:isize))
call random_seed(get=gseed(1:isize))
call random_number(harvest=ran_harvest)
write(10,*),'seed gseed',seed,gseed
write(10,*),"ran_harvest"
write(10,*),ran_harvest
call random_seed(get=gseed(1:isize))
write(10,*),'gseed after harvest',gseed
close(10)
stop
end program main
size 2
hiseed gseed -1 -1 171 499
zseed gseed 0 0 2147483562 2147483398
seed gseed 123456789 987654321 123456789 987654321
ran_harvest
0.6099895 0.9807593 0.2936640 0.9100145 0.8464803
0.4358687 2.5444608E-02 0.5457680 0.6483381 0.3045360
gseed after harvest 375533067 1869030476
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you elaborate on your question? What do you expect to see?
The purpose of RANDOM_SEED is to allow you to set the state of the random sequence to a known position. If you PUT the same seed, then ask for random_number, you should get the same value. I have not studied the code in detail, but it would not surprise me if it did not take your input seeds verbatim - it might need to do something to make them fit within the range required by the algorithm.
The purpose of RANDOM_SEED is to allow you to set the state of the random sequence to a known position. If you PUT the same seed, then ask for random_number, you should get the same value. I have not studied the code in detail, but it would not surprise me if it did not take your input seeds verbatim - it might need to do something to make them fit within the range required by the algorithm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for an un-clear question.
put argument is used to reset the value of the seed. get is used to inquire the current value of the seed. In the example, hiseed, zseed, and seed are put to set the seed, respectively; and gseed is used to get the seed after put everytime. But the results are confusing.
the values of hiseed and zseed are /-1,-1/ and /0,0/, the gseed values gotten by get are /171,499/, and /2147483562,2147483398/, respectively. However, gseed has the same value as seed when seed is put by seed which has the value of /123456789,987654321/. Why?
put argument is used to reset the value of the seed. get is used to inquire the current value of the seed. In the example, hiseed, zseed, and seed are put to set the seed, respectively; and gseed is used to get the seed after put everytime. But the results are confusing.
the values of hiseed and zseed are /-1,-1/ and /0,0/, the gseed values gotten by get are /171,499/, and /2147483562,2147483398/, respectively. However, gseed has the same value as seed when seed is put by seed which has the value of /123456789,987654321/. Why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
size 2
hiseed gseed -1 -1 171 499
zseed gseed 0 0 2147483562 2147483398
From the documentation (where PUT sets the current seed and GET returns the current seed)
PUT followed by immediate GET (twice)
I would have expected to see
size 2
hiseed gseed -1 -1 -1 -1
zseed gseed 0 0 0 0
The next lineshows the expected values :
seed gseed 123456789 987654321 123456789 987654321
ie the pairs of numbers are the same.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. This is exactly my question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'll look at the code when I get back to the office next week, but my guess is that random_seed "adjusts" the seed value if it is not within the range required by the algorithm. 0 or -1 would certainly be out of range.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes. You are right. I read the document again and found the ranges for the two seeds are [1,2147483562] and [1,2147483398]. If the used assigned seed is out of range, the seed might be chosen using the system clock or other mechanism.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I looked at the code. If either seed value is zero, it uses a fixed initial seed. If either seed value is greater than (unsigned) the maximum seed value, the value is reduced by subtraction to be within range. If you pass no arguments to RANDOM_SEED, the seed is initialized based on the system clock. Note that this last behavior is NOT specified by the standard, but it is allowed and seems to be what most people want.

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