- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i have the following code to re-seed a random number stream:
subroutine SetSeed (seed)
!i have the relevant meta commands in here
use DFPORT
real(4) seed
call SRAND(seed)
end
I have compiled this and created a debug version of the DLL, which i call from VB. When i execute the line
call SRAND(seed)
a dialogue box appears asking me to specify a path for the library file DFPORT.FOR. The library file I have installed on my machine is DFPORT.F90, as I would have expected, and so I can not get this line to execute and re-seed the random number.
I have the same problem with the function to generate the random number which uses DRAND().
What am I doing wrong ?
Thanks
Phil.
subroutine SetSeed (seed)
!i have the relevant meta commands in here
use DFPORT
real(4) seed
call SRAND(seed)
end
I have compiled this and created a debug version of the DLL, which i call from VB. When i execute the line
call SRAND(seed)
a dialogue box appears asking me to specify a path for the library file DFPORT.FOR. The library file I have installed on my machine is DFPORT.F90, as I would have expected, and so I can not get this line to execute and re-seed the random number.
I have the same problem with the function to generate the random number which uses DRAND().
What am I doing wrong ?
Thanks
Phil.
Link Copied
9 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an afterthought - dont know if it is relevant, but i am using windows 2k, and compaq vf professional 6.1.0.
phil
phil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use Step Over, not Step Into. You're stepping into the source of SRAND, which isn't available to you.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks - the seeder seems to work ok. now having problems with the generator - I want double precision random numbers, so i am using DRAND in the following DLL function:
function GetRand()
use DFPORT
!DEC$ attributes dllexport :: GetRand
!DEC$ attributes alias : "GetRand" :: GetRand
real(8) GetRand
GetRand = DRAND(0)
return
end
When i call the dll function from XL I get an access violation error ????
grateful for any help.
phil.
function GetRand()
use DFPORT
!DEC$ attributes dllexport :: GetRand
!DEC$ attributes alias : "GetRand" :: GetRand
real(8) GetRand
GetRand = DRAND(0)
return
end
When i call the dll function from XL I get an access violation error ????
grateful for any help.
phil.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you declared the value returned by GetRand as double precision in Excel?
Mike
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks - but i had the following VBA declare statement, which does as you suggest, i think...
Declare Function GetRand _
Lib "h:...simstuff.DLL" () As Double
I have another couple of things to check but it looks OK to me ??
obviously any other ideas would be gratefully received - getting this working is rather a fundamental element of what I am trying to do.
phil.
Declare Function GetRand _
Lib "h:...simstuff.DLL" () As Double
I have another couple of things to check but it looks OK to me ??
obviously any other ideas would be gratefully received - getting this working is rather a fundamental element of what I am trying to do.
phil.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the one other aspect of this i am not sure about is how the random no generator uses the seed to control the stream of random numbers. Am i doing this correctly ?
First I call the seeding subroutine:
subroutine SetSeed (seed)
use DFPORT
real(4) seed
call SRAND(seed)
end
from the VB sub:
Sub vbSetSeed()
Dim X As Single
X = Range("Seed").Value
Call SetSeed(X)
End Sub
(which seems to be working)
Then I execute a function call from VB to ask for the random number from the seeded stream:
VBGetRand = GetRand()
where GetRand is as described in the previous post.
Is this use of SRAND(seed) and DRAND(0) consistent ?
thanks again
Phil.
First I call the seeding subroutine:
subroutine SetSeed (seed)
use DFPORT
real(4) seed
call SRAND(seed)
end
from the VB sub:
Sub vbSetSeed()
Dim X As Single
X = Range("Seed").Value
Call SetSeed(X)
End Sub
(which seems to be working)
Then I execute a function call from VB to ask for the random number from the seeded stream:
VBGetRand = GetRand()
where GetRand is as described in the previous post.
Is this use of SRAND(seed) and DRAND(0) consistent ?
thanks again
Phil.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you considered using the standard Fortran intrinsic RANDOM_NUMBER (and RANDOM_SEED) instead? It's a better generator and is probably easier to understand.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i might have to try it - can i use RANDOM_NUMBER to generate real(8) rather than real(4) numbers ? Also, because I have to generate a very large number of random nos, i have done a bit of work testing the true randomness of the rand() stream and it seems to be quite good. I do not know if random_number is as good - i am pretty wary of most pseudo rn generators.
Also I'd still like to understand why my use of SRAND and DRAND is not working.
Phil
Also I'd still like to understand why my use of SRAND and DRAND is not working.
Phil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, RANDOM_NUMBER can return REAL(8). It's a very good generator - L'Ecuyer '83.
Steve
Steve

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