CXML
ran16807
Routine to generate single precision random numbers using
a=16807 and m=2**31-1
FORMAT
RAN16807 (s)
Function Value
ran16807 real*4
The uniform[0,1] value returned.
Arguments
s integer*4
On entry, the seed s>=1.
On exit, the updated seed.
Description
The RAN16807 routine implements the "minimal standard" or Lehmer
multiplicative generator to compute updated seeds using a=16807, m=2**31-1,
as follows:
s = 16807*s mod 2**31-1
and returns s*(1.0/m) as its uniform[0,1] output.
The following code example simulates a random walk using RAN16807. A
particle starts at (0,0) and proceeds N., E., S., or W. with probability
0.25 each.
Example
integer ix,iy,i,j,iseed,nsteps,nwalks
real*4 x
c random walk: go N E S W each with probability 0.25
nsteps = 1000000
nwalks = 10
iseed = 1234
do j=1,nwalks
ix=0
iy=0
do i = 1, nsteps
x=ran16807(iseed)
if(x.le.0.25)then
ix=ix+1
else if(x.le.0.5)then
iy=iy+1
else if(x.le.0.75)then
ix=ix-1
else
iy=iy-1
end if
end do
print*,'final position ',ix,iy
end do
end
CXML Home Page Index of CXML Routines