- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We are in the process of porting over some code from Linux Fortran to 32-bit Windows Fortran, and we're at a point where we use the rand() functionality. We call rand(0), which we're expecting to produce a real number between 0.0 and 1.0. However, the result ends up being NaN. Still troubleshooting into this. What could be up with rand() that we get NaN? Do we need to install a library someplace to allow this to happen correctly?
-Michael
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
More info... It looks like we're calling rand() something like this,
real :: temp
! ...
temp= rand(0)
Which returns NaN.
integer :: temp
! ...
temp= rand(0)
Which returns MIN_INT or something like, -2147483648.
This doesn't look quite right. Note this works on the Linux platform, not using the Intel compiler I gather (?).
Are we doing something wrong? Do we need to call it differently? Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can try, as an experiment, adding:
use ifport
in the routine that calls rand. This is not required, but it might identify a coding error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually, we've decided to make use of random_number() instead of rand() as this better meets the business requirement.
FYI, for what it's worth, stepping into the rand() call, we end up in a C-style function, which accepts an integer and returns an integer. Not sure why this is or how it is possibly being mangled on the return to the Fortran caller, however.
As far as example code goes, I posted a snippet representing what code was being used to generate rand() values. It's pretty straightforward. That was it.
At any rate, a non issue as far as our code is concerned. random_number() and not rand() produces the results we're looking for.
-Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page