Jump to content
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
HP.com home

Transition Impacts

Tru64 UNIX Software Transition Kit
» 

DSPP Home

» HP STK home
Tru64 UNIX STK
» Home
» Overview
» Tools
» Documentation
» Transition impacts
» Identifier types
» Impact list
» Porting to HP-UX
» FAQ
» Glossary
» Help
» Send us feedback
Site maps
» Tru64 UNIX STK
» DSPP
Content starts here

critical impact:

RANDOM_SEED - some behavioral differences (CrCh324)

F90 Impacts

Problem description

The behavior of RANDOM_SEED is different on Tru64 UNIX and HP-UX.

RANDOM_SEED([SIZE] [, PUT] [, GET]) changes or queries the seed (starting point) for the pseudorandom number generator used by RANDOM_NUMBER. It requires that the size of the array be at least as long as the value N returned by RANDOM_SEED with parameter SIZE.

On Tru64 UNIX this number is 2. The following example executes without error with Compaq Fortran, but will generate an error with HP Fortran.

Identifiers

Fortran Intrinsic SubroutinesRANDOM_SEED      

Old behavior

PROGRAM TESTRAN
   REAL*4 RSHORT
   REAL*8 RLONG
   INTEGER :: SEED_SIZE, I, J
   INTEGER, DIMENSION(10) :: MYSEED
   SEED_SIZE = 2
   MYSEED(1) = 1641671953
   MYSEED(2) = 407586285
   PRINT *,MYSEED(1),MYSEED(2)
   CALL RANDOM_SEED(PUT = MYSEED(1:SEED_SIZE))
   CALL RANDOM_NUMBER(RSHORT)
   CALL RANDOM_SEED(PUT = MYSEED(1:SEED_SIZE))
   CALL RANDOM_NUMBER(RLONG)
   PRINT *,RSHORT, RLONG
   IF(RSHORT .gt. RLONG) PRINT *,'ERROR'
END PROGRAM TESTRAN

See also

Solution description

On HP-UX, this number is generally or at least 17. To be safe, programs should not rely upon the seed being any particular size, but should query for the seed size instead.

A runtime error will be generated if SIZE less than 17 is provided to the PUT parameter. In such a case, make changes to the code as suggested in the following example:

New behavior

PROGRAM TESTRAN
   REAL*4 RSHORT
   REAL*8 RLONG
   INTEGER :: SEED_SIZE, I
   INTEGER :: MYSEED1, MYSEED2
   MYSEED1 = 1641671953
   MYSEED2 = 407586285
   PRINT *,MYSEED1,MYSEED2
   CALL RANDOM_SEED(SIZE = I)
   CALL SET_SEED(I,MYSEED1,MYSEED2)
   CALL RANDOM_NUMBER(RSHORT)
   CALL SET_SEED(I,MYSEED1,MYSEED2)
   CALL RANDOM_NUMBER(RLONG)
   PRINT *,RSHORT, RLONG
   IF(RSHORT .gt. RLONG) PRINT *,'ERROR'
END PROGRAM TESTRAN
SUBROUTINE SET_SEED(SEED_SIZE, MYSEED1,MYSEED2)
  INTEGER :: SEED_SIZE
  INTEGER :: MYSEED1,MYSEED2
  INTEGER, DIMENSION(SEED_SIZE) :: RAN_SEED
  RAN_SEED = 0
  RAN_SEED(1) = MYSEED1
  RAN_SEED(2) = MYSEED2
  PRINT *,RAN_SEED
  CALL RANDOM_SEED(PUT=RAN_SEED)
END SUBROUTINE

See also


Problem summary

classifications source types OS release severity type
F90 Fortran any HP-UX 11i version critical changed
Printable version
Privacy statement Using this site means you accept its terms Feedback to DSPP
© 2007 Hewlett-Packard Development Company, L.P.