      SUBROUTINE RANPER(N,ISTART,X)
C
C     PURPOSE--THIS SUBROUTINE GENERATES A RANDOM PERMUTATION OF SIZE N
C              OF THE VALUES 1.0, 2.0, 3.0, ..., N-1, N.
C     INPUT  ARGUMENTS--N      = THE DESIRED INTEGER SIZE
C                                OF THE RANDOM 1 TO N PERMUTATION.
C                     --ISTART = AN INTEGER FLAG CODE WHICH 
C                                (IF SET TO 0) WILL START THE
C                                GENERATOR OVER AND HENCE
C                                PRODUCE THE SAME RANDOM PERMUTATION
C                                OVER AND OVER AGAIN
C                                UPON SUCCESSIVE CALLS TO
C                                THIS SUBROUTINE WITHIN A RUN; OR
C                                (IF SET TO SOME INTEGER
C                                VALUE NOT EQUAL TO 0,
C                                LIKE, SAY, 1) WILL ALLOW
C                                THE GENERATOR TO CONTINUE
C                                FROM WHERE IT STOPPED
C                                AND HENCE PRODUCE DIFFERENT
C                                RANDOM PERMUTATIONS UPON
C                                SUCCESSIVE CALLS TO
C                                THIS SUBROUTINE WITHIN A RUN.
C     OUTPUT ARGUMENTS--X      = A SINGLE PRECISION VECTOR
C                                (OF DIMENSION AT LEAST N)
C                                INTO WHICH THE GENERATED
C                                RANDOM PERMUTATION WILL BE PLACED.
C     OUTPUT--A RANDOM PERMUTATION OF SIZE N
C             OF THE VALUES 1.0, 2.0, 3.0, ..., N-1, N.
C     PRINTING--NONE UNLESS AN INPUT ARGUMENT ERROR CONDITION EXISTS. 
C     RESTRICTIONS--THERE IS NO RESTRICTION ON THE MAXIMUM VALUE
C                   OF N FOR THIS SUBROUTINE.
C     OTHER DATAPAC   SUBROUTINES NEEDED--UNIRAN. 
C     FORTRAN LIBRARY SUBROUTINES NEEDED--NONE.
C     MODE OF INTERNAL OPERATIONS--SINGLE PRECISION.
C     LANGUAGE--ANSI FORTRAN. 
C     COMMENT--ALGORITHM SUGGESTED BY DAN LOZIER, 
C              NATIONAL BUREAU OF STANDARDS (205.01).
C     REFERENCES--NONE.
C     WRITTEN BY--JAMES J. FILLIBEN
C                 STATISTICAL ENGINEERING LABORATORY (205.03)
C                 NATIONAL BUREAU OF STANDARDS
C                 WASHINGTON, D. C. 20234
C                 PHONE:  301-921-2315
C     ORIGINAL VERSION--JUNE      1972. 
C     UPDATED         --MAY       1974. 
C     UPDATED         --SEPTEMBER 1975. 
C     UPDATED         --NOVEMBER  1975. 
C
C---------------------------------------------------------------------
C
      DIMENSION X(1)
      DIMENSION U(1)
C
      AN=N
      IPR=6
C
C     CHECK THE INPUT ARGUMENTS FOR ERRORS
C
      IF(N.LT.1)GOTO50
      IF(N.EQ.1)GOTO55
      GOTO90
   50 WRITE(IPR, 5) 
      WRITE(IPR,47)N
      RETURN
   55 WRITE(IPR, 8) 
      X(1)=1
      RETURN
   90 CONTINUE
    5 FORMAT(1H , 91H***** FATAL ERROR--THE FIRST  INPUT ARGUMENT TO THE
     1 RANPER SUBROUTINE IS NON-POSITIVE *****)
    8 FORMAT(1H ,100H***** NON-FATAL DIAGNOSTIC--THE FIRST  INPUT ARGUME
     1NT TO THE RANPER SUBROUTINE HAS THE VALUE 1 *****)
   47 FORMAT(1H , 35H***** THE VALUE OF THE ARGUMENT IS ,I8   ,6H *****)
C
C-----START POINT-----------------------------------------------------
C
      CALL UNIRAN(1,ISTART,U) 
C
      DO100I=1,N
      X(I)=I
  100 CONTINUE
C
      DO200I=1,N
      CALL UNIRAN(1,1,U)
      ADD=AN*U(1)+1.0
      IADD=ADD
      IF(IADD.LT.1)IADD=1
      IF(IADD.GT.N)IADD=N
      J=I+IADD
      IF(J.GT.N)J=J-N
      HOLD=X(J)
      X(J)=X(I)
      X(I)=HOLD
  200 CONTINUE
      RETURN
      END 
