160 integer,
intent(out),
optional:: size
161 integer,
intent(in),
optional:: put(nrest)
162 integer,
intent(out),
optional:: get(nrest)
164 if(
present(size))
then
168 elseif(
present(put))
then
171 if(
present(stat))
then
175 stat%gset=transfer(put(n+3:nrest),stat%gset)
176 if(stat%mti.lt.0.or.stat%mti.gt.n.or.any(stat%mt.eq.0).or.
177 & stat%iset.lt.0.or.stat%iset.gt.1)
then
178 call random_setseed_t(iseed,stat)
185 sstat%gset=transfer(put(n+3:nrest),sstat%gset)
186 if(sstat%mti.lt.0.or.sstat%mti.gt.n.or.any(sstat%mt.eq.0)
187 & .or.sstat%iset.lt.0.or.sstat%iset.gt.1)
then
188 call random_setseed_t(iseed,sstat)
192 elseif(
present(get))
then
193 if(
present(stat))
then
194 if(stat%mti.eq.n+1)
call random_setseed_t(iseed,stat)
198 get(n+3:nrest)=transfer(stat%gset,get,nrest-(n+3)+1)
200 if(sstat%mti.eq.n+1)
call random_setseed_t(iseed,sstat)
204 get(n+3:nrest)=transfer(sstat%gset,get,nrest-(n+3)+1)
207 if(
present(stat))
then
208 call random_setseed_t(iseed,stat)
210 call random_setseed_t(iseed,sstat)
289 subroutine random_number_t(harvest,stat)
291 real,
intent(out):: harvest(:)
294 integer tshftu,tshfts,tshftt,tshftl
295 tshftu(y)=ishft(y,-11)
297 tshftt(y)=ishft(y,15)
298 tshftl(y)=ishft(y,-18)
300 if(stat%mti.ge.n)
then
302 y=ior(iand(stat%mt(kk),umask),iand(stat%mt(kk+1),lmask))
303 stat%mt(kk)=ieor(ieor(stat%mt(kk+m),ishft(y,-1)),
307 y=ior(iand(stat%mt(kk),umask),iand(stat%mt(kk+1),lmask))
308 stat%mt(kk)=ieor(ieor(stat%mt(kk+(m-n)),ishft(y,-1)),
311 y=ior(iand(stat%mt(n-1),umask),iand(stat%mt(0),lmask))
312 stat%mt(n-1)=ieor(ieor(stat%mt(m-1),ishft(y,-1)),
318 y=ieor(y,iand(tshfts(y),tmaskb))
319 y=ieor(y,iand(tshftt(y),tmaskc))
322 harvest(j)=(real(y)+2.0**32)/(2.0**32-1.0)
324 harvest(j)=real(y)/(2.0**32-1.0)
373 subroutine random_gauss_t(harvest,stat)
375 real,
intent(out):: harvest(:)
382 if(stat%iset.eq.1)
then
389 call random_number_t(harvest(mx+1:my),stat)
391 call rgauss(harvest(j+1),harvest(j+2),r,g1,g2)
402 call random_number_t(r2,stat)
403 call rgauss(r2(1),r2(2),r,g1,g2)
420 subroutine rgauss(r1,r2,r,g1,g2)
421 real,
intent(in):: r1,r2
422 real,
intent(out):: r,g1,g2
428 fac=sqrt(-2.*log(r)/r)
456 subroutine random_index_i(imax,iharvest,inseed)
458 integer,
intent(in):: imax
459 integer,
intent(out):: iharvest(:)
460 integer,
intent(in):: inseed
462 call random_setseed_t(inseed,stat)
463 call random_index_t(imax,iharvest,stat)
471 subroutine random_index_s(imax,iharvest)
473 integer,
intent(in):: imax
474 integer,
intent(out):: iharvest(:)
475 if(sstat%mti.eq.n+1)
call random_setseed_t(iseed,sstat)
476 call random_index_t(imax,iharvest,sstat)
485 subroutine random_index_t(imax,iharvest,stat)
487 integer,
intent(in):: imax
488 integer,
intent(out):: iharvest(:)
490 integer,
parameter:: mh=n
496 call random_number_t(h(:i2-(i1-1)),stat)
497 iharvest(i1:i2)=max(ceiling(h(:i2-(i1-1))*imax),1)