draw random number from array



Hello,
I think that this is a straight forward question but I'm stumped. In my
program I have created an array based on a Gaussian distribution. From
this array I would like to draw a single number randomly to use in
further calculations. To do this I have written a program that
generates an array of index values with the random number 'seeded'
based on the intrinsic function secnds(x). However, the initial index
value stays constant while the rest vary from run to run (program is
posted below).
I have two questions: 1) is there a better approach to randomly draw a
number from an array?
and 2) why does the initial value remain constant for each run when the
'seed' should be changing?

Thank you for your time,
MaxNDaisy

program test_index
integer, parameter::n=5
integer, dimension(n) :: index_num
real, dimension(n) :: q
real:: finq

q=(/0.3979,0.471,0.5106,0.6677,0.4706/)
write(6,*) q
call random_index (index_num,n)

write(6,*) 'q(2)=', q(2)
finq=q(index_num(2))
write(6,*) 'finq=q(index_num(2))', finq

end program test_index

subroutine random_index(index_num,n)
integer, dimension(n) :: index_num
integer seed,seed1, n, i_index ,j
real x
seed1=7654321
x=0.0
! seed should be set to a large odd integer according to the manual
! secnds(x) gives number of seconds-x elapsed since midnight
! the 2*int(secnds(x)) is always even (int=gives integer) so seed is
always odd

seed=seed1+2*int(secnds(x))

do j=1,n

i_index=(n*ran(seed))+1

index_num(j)=i_index
write(6,*) j, i_index


enddo
write(6,*) 'index_num', index_num
return
end subroutine random_index

.



Relevant Pages

  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.fortran)
  • VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.basic.visual.misc)
  • Re: VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.basic.visual.misc)
  • Re: memory leak help!
    ... a loop from the main program. ... REPLACE THE NEW COMPLEX INTO ORIGINAL ARRAY x ... END OF SUBROUTINE SCEUA ... IMPLICIT NONE ...
    (comp.lang.fortran)
  • VB .Net and Intel Visual Fortran 9
    ... having is that the VB program cannot load the DLL. ... subroutine) to accept an array from VB - in my case a 2D array. ... Declare Sub mmult Lib "test.dll" (ByRef i As Double, ByRef j As Double, ...
    (comp.lang.fortran)