ccccccccccccccccccccccccc     Program 4.6     cccccccccccccccccccccccccc
c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c                                                                      c
c Please Note:                                                         c
c                                                                      c
c (1) This computer program is part of the book, "An Introduction to   c
c     Computational Physics," written by Tao Pang and published and    c
c     copyrighted by Cambridge University Press in 1997.               c
c                                                                      c
c (2) No warranties, express or implied, are made for this program.    c
c                                                                      c
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c
      SUBROUTINE RMSG (N,XS,A)
C
C Subroutine for generating a random matrix in the Gaussian
C orthogonal ensemble with XS as the standard deviation of 
C the off-diagonal elements.
C
      DIMENSION A(N,N)
      COMMON /CSEED/ ISEED
C
      DO     100 I = 1, N
          CALL GRNF(G1,G2)
          A(I,I) = SQRT(2.0)*G1*XS
  100   CONTINUE
      DO     300 I = 1, N
        DO   200 J = I+1, N 
          CALL GRNF(G1,G2)
          A(I,J) = G1*XS
          A(J,I) = A(I,J)
  200   CONTINUE
  300 CONTINUE
      RETURN
      END
C
      SUBROUTINE GRNF(X,Y)
      COMMON /CSEED/ ISEED
        PI = 4.0*ATAN(1.0)
        R1 = -ALOG(1.0-RANF())
        R2 = 2.0*PI*RANF()
        R1 = SQRT(2.0*R1)
        X  = R1*COS(R2)
        Y  = R1*SIN(R2)
      RETURN
      END
C
      FUNCTION RANF()
      DATA IA/16807/,IC/2147483647/,IQ/127773/,IR/2836/
      COMMON /CSEED/ ISEED
        IH = ISEED/IQ
        IL = MOD(ISEED,IQ)
        IT = IA*IL-IR*IH
        IF(IT.GT.0) THEN
          ISEED = IT
        ELSE
          ISEED = IC+IT
        END IF
        RANF = ISEED/FLOAT(IC)
      RETURN
      END
