View Single Post
  #1 (permalink)  
Old 09-14-2006, 07:29 PM
PCAT
Guest
 
Posts: n/a
Default seed problem in a random number generator subroutine

I have a random digit number generator subroutine and a seed file
When the seed file number dseed=1620617369.0000, the simulation stopped
running.
Does anyone know what happened and how to fix it?
I wonder if it is the seed value problem or it is something else.
Thank you very much!






double precision dseed
double precision aa,mm
real zz(2),uu(2)
common/ranparm/aa,mm
common/ramsave/zz
mm=dble((2.0d0)**31-1.d0)
aa=dble((7.0d0)**5)

open (22,file='seed.txt')
read (22,*)dseed
rewind(22)

call digran(dseed,p,q,y)

write(22,*)dseed
close(22)
end

c---------------------------------
c generates n random numbers from U(0,1),
c and stores them in array u(n).
subroutine rangen(dseed,n,u)
real u(n)
double precision dseed,aa,mm
common/ranparm/aa,mm

do 10 i=1,n
dseed=dmod(aa*dseed,mm)
u(i)=sngl(dseed/mm)
10 continue
c---------------------------------------
return
end

c --------------------------------------------------
c generate random digital number between p and q
c p < q
c output =iy
c --------------------------------------------------
subroutine digran(dseed,p,q,iy)
double precision dseed
real y
real p,q
integer iy

call rangen(dseed,1,y)
iy=p + nint(y* (q-p+1.))

if (iy > q) then
iy= q
else if (iy < p) then
iy=p
endif

return
end

Reply With Quote