- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I tried to use the subroutine RANDOM of the IFORT-Compiler 10.0. The Language Reference said it would return a random number reater than or equal to
zero and less than one from the uniform distribution. But I also got the value 1.
Which Subroutine should I use with openmp. Cause RANDOM_NUMBER returns the same sequence in each thread.
Thanks
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could use RANDOM_SEED in each parallel region to vary the starting point of RANDOM_NUMBER.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
One other question I have is how you determined that you got an exact value of 1.0. Did you print the hex for the real value, did you write(*,*) or print*, did you print using a F format, or did you use a comparison of some sort IF ( x .eq. 1 ) THEN etc.
I would like to determine if there is a bug with our random_number, since the spec requires that it is strictly < 1
I would like to determine if there is a bug with our random_number, since the spec requires that it is strictly < 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
what I tried to do is to create an random integer with an upper bound which was used as an array index. I wrote a function like
REAL :: rr
CALL RANDOM(rr)
intValue = INT(rr * upperbound) + 1
But the intValue in some cases was one larger than the arraybounds. So I tried to find the error with:
PROGRAM test
USE IFPORT
IMPLICIT NONE
REAL :: zufall
CALL SEED(1)
DO
CALL RANDOM(zufall)
IF(zufall .GE. 1.0) THEN
WRITE(*,*) 'jetzt', zufall
exit
END IF
END DO
END PROGRAM test
And there was an output with 1.000000 . Did I something wrong?
Andreas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suggest using RANDOM_NUMBER and call RANDOM_SEED with no arguments just once at the beginning of the program.
Writing the value using list-directed output may cause rounding As suggested, you want to write it in hex form, or perhaps to many digits (at least 10).
Writing the value using list-directed output may cause rounding As suggested, you want to write it in hex form, or perhaps to many digits (at least 10).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You probably discovered this, but just to document this thread for the next user who comes along:
RANDOM and RAND are functions from the Portability library, IFPORT. These return a number in the range 0.0 to 1.0 INCLUSIVE. So 1.0 is a valid return for RANDOM.
The Fortran 90 intrinsic, random_number, returns 0.0 <= number < 1.0, which is what you were looking for.
ron
RANDOM and RAND are functions from the Portability library, IFPORT. These return a number in the range 0.0 to 1.0 INCLUSIVE. So 1.0 is a valid return for RANDOM.
The Fortran 90 intrinsic, random_number, returns 0.0 <= number < 1.0, which is what you were looking for.
ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
just to get this right. There are two functions RANDOM and RAND from the IFPORT library that return 0<=value<=1.
But there is also a SUBROUTINE RANDOM from the IFPORT library that returns 0<=value<1 (Language Reference - Document Number: 253261-006US - page 1159) like the subroutine RANDOM_NUMBER. And I tried to use the subroutine that should not give a one.
So 1.0 is a valid return for the function RANDOM but not for the subroutine. Is this right or am I wrong?
Andreas
just to get this right. There are two functions RANDOM and RAND from the IFPORT library that return 0<=value<=1.
But there is also a SUBROUTINE RANDOM from the IFPORT library that returns 0<=value<1 (Language Reference - Document Number: 253261-006US - page 1159) like the subroutine RANDOM_NUMBER. And I tried to use the subroutine that should not give a one.
So 1.0 is a valid return for the function RANDOM but not for the subroutine. Is this right or am I wrong?
Andreas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The documentation supports your description. I don't entirely trust the description of the function RANDOM but it may be correct - I'll play with that and see. But I do strongly recommend using RANDOM_NUMBER instead.

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