220 subroutine random_seed(size,put,get,stat)
222 integer,
intent(out),
optional:: size
223 integer,
intent(in),
optional:: put(nrest)
224 integer,
intent(out),
optional:: get(nrest)
226 if(
present(size))
then
230 elseif(
present(put))
then
233 if(
present(stat))
then
237 stat%gset=transfer(put(n+3:nrest),stat%gset)
238 if(stat%mti.lt.0.or.stat%mti.gt.n.or.any(stat%mt.eq.0).or.
239 & stat%iset.lt.0.or.stat%iset.gt.1)
then
240 call random_setseed_t(iseed,stat)
247 sstat%gset=transfer(put(n+3:nrest),sstat%gset)
248 if(sstat%mti.lt.0.or.sstat%mti.gt.n.or.any(sstat%mt.eq.0)
249 & .or.sstat%iset.lt.0.or.sstat%iset.gt.1)
then
250 call random_setseed_t(iseed,sstat)
254 elseif(
present(get))
then
255 if(
present(stat))
then
256 if(stat%mti.eq.n+1)
call random_setseed_t(iseed,stat)
260 get(n+3:nrest)=transfer(stat%gset,get,nrest-(n+3)+1)
262 if(sstat%mti.eq.n+1)
call random_setseed_t(iseed,sstat)
266 get(n+3:nrest)=transfer(sstat%gset,get,nrest-(n+3)+1)
269 if(
present(stat))
then
270 call random_setseed_t(iseed,stat)
272 call random_setseed_t(iseed,sstat)
330 subroutine random_number_t(harvest,stat)
332 real(kind_dbl_prec),
intent(out):: harvest(:)
335 integer tshftu,tshfts,tshftt,tshftl
336 tshftu(y)=ishft(y,-11)
338 tshftt(y)=ishft(y,15)
339 tshftl(y)=ishft(y,-18)
341 if(stat%mti.ge.n)
then
343 y=ior(iand(stat%mt(kk),umask),iand(stat%mt(kk+1),lmask))
344 stat%mt(kk)=ieor(ieor(stat%mt(kk+m),ishft(y,-1)),
348 y=ior(iand(stat%mt(kk),umask),iand(stat%mt(kk+1),lmask))
349 stat%mt(kk)=ieor(ieor(stat%mt(kk+(m-n)),ishft(y,-1)),
352 y=ior(iand(stat%mt(n-1),umask),iand(stat%mt(0),lmask))
353 stat%mt(n-1)=ieor(ieor(stat%mt(m-1),ishft(y,-1)),
359 y=ieor(y,iand(tshfts(y),tmaskb))
360 y=ieor(y,iand(tshftt(y),tmaskc))
363 harvest(j)=(real(y,kind=kind_dbl_prec)+ &
364 & 2.0_kind_dbl_prec**32)/ &
365 & (2.0_kind_dbl_prec**32-1.0_kind_dbl_prec)
367 harvest(j)=real(y)/(2.0_kind_dbl_prec**32- &
403 subroutine random_gauss_t(harvest,stat)
405 real(kind_dbl_prec),
intent(out):: harvest(:)
408 real(kind_dbl_prec) :: r2(2),r,g1,g2
412 if(stat%iset.eq.1)
then
419 call random_number_t(harvest(mx+1:my),stat)
421 call rgauss(harvest(j+1),harvest(j+2),r,g1,g2)
432 call random_number_t(r2,stat)
433 call rgauss(r2(1),r2(2),r,g1,g2)
442 subroutine rgauss(r1,r2,r,g1,g2)
443 real(kind_dbl_prec),
intent(in):: r1,r2
444 real(kind_dbl_prec),
intent(out):: r,g1,g2
445 real(kind_dbl_prec) :: v1,v2,fac
446 v1=2._kind_dbl_prec*r1-1._kind_dbl_prec
447 v2=2._kind_dbl_prec*r2-1._kind_dbl_prec
450 fac=sqrt(-2._kind_dbl_prec*log(r)/r)
469 subroutine random_index_i(imax,iharvest,inseed)
471 integer,
intent(in):: imax
472 integer,
intent(out):: iharvest(:)
473 integer,
intent(in):: inseed
475 call random_setseed_t(inseed,stat)
476 call random_index_t(imax,iharvest,stat)
480 subroutine random_index_s(imax,iharvest)
482 integer,
intent(in):: imax
483 integer,
intent(out):: iharvest(:)
484 if(sstat%mti.eq.n+1)
call random_setseed_t(iseed,sstat)
485 call random_index_t(imax,iharvest,sstat)
489 subroutine random_index_t(imax,iharvest,stat)
491 integer,
intent(in):: imax
492 integer,
intent(out):: iharvest(:)
494 integer,
parameter:: mh=n
496 real(kind_dbl_prec) :: h(mh)
500 call random_number_t(h(:i2-(i1-1)),stat)
501 iharvest(i1:i2)=max(ceiling(h(:i2-(i1-1))*imax),1)