FOR$RANDOM      ; random number generator and interfaces         21-AUG-1978 18:56:24   VAX-11 MACRO X0.3-11               Page   0

TABLE OF CONTENTS   



   (2)     100  HISTORY		; Detailed Current Edit History

   (3)     100  DECLARATIONS

   (4)     100  FOR$RANDU and FOR$RANDU_W	return number as para

   (5)     100  FOR$IRAN	  result in R0

FOR$RANDOM      ; random number generator and interfaces         21-AUG-1978 18:56:24   VAX-11 MACRO X0.3-11               Page   1

0-11                                                                                                                             (1)



                                     0000   100 	.TITLE	FOR$RANDOM	; random number generator and interfaces

                                     0000   200 	.IDENT	/0-11/		; File: FORRANDOM.MAR

                                     0000   300 

                                     0000   400 ;

                                     0000   500 ; Copyright (C) 1977

                                     0000   600 ; Digital Equipment Corporation, Maynard, Massachusetts 01754

                                     0000   700 ;

                                     0000   800 ; This software is furnished under a license for use only on a single

                                     0000   900 ; computer  system  and  may be copied only with the inclusion of the

                                     0000  1000 ; above copyright notice. This software, or any other copies thereof,

                                     0000  1100 ; may not be provided or otherwise made available to any other person

                                     0000  1200 ; except for use on such system and to one who agree to these license 

                                     0000  1300 ; terms.  Title to  and  ownership of the software shall at all times 

                                     0000  1400 ; remain in DEC.

                                     0000  1500 ;

                                     0000  1600 ; The information in the software is subject to change without notice

                                     0000  1700 ; and should  not  be construed  as a commitment by Digital Equipment 

                                     0000  1800 ; Corporation.

                                     0000  1900 ;

                                     0000  2000 ; DEC assumes  no  responsibility  for the use or  reliability of its

                                     0000  2100 ; software on equipment which is not supplied by DEC.

                                     0000  2200 ;

                                     0000  2300 ;

                                     0000  2400 ; FACILITY: FORTRAN SYSTEM LIBRARY

                                     0000  2500 ;++

                                     0000  2600 ; ABSTRACT:

                                     0000  2700 ;

                                     0000  2800 ;	Provide entry points for:

                                     0000  2900 ;		FOR$IRAN

                                     0000  3000 ;		FOR$RANDU_W

                                     0000  3100 ;

                                     0000  3200 ;	The algorithm used is copied exactly from PDP-11 FORTRAN

                                     0000  3300 ;	library so the same sequences will be generated.

                                     0000  3400 ;--

                                     0000  3500 ;

                                     0000  3600 ; VERSION: 0

                                     0000  3700 ;

                                     0000  3800 ; HISTORY:

                                     0000  3900 ;

                                     0000  4000 ; AUTHOR:

                                     0000  4100 ;	Jonathan M. Taylor, 12-Aug-77: Version 0

                                     0000  4200 ;

                                     0000  4300 ; MODIFIED BY:

                                     0000  4400 ;

                                     0000  4500 ;

                                     0000  4600 ;

FOR$RANDOM      ; random number generator and interfaces         21-AUG-1978 18:56:24   VAX-11 MACRO X0.3-11               Page   2

0-11            HISTORY  ; Detailed Current Edit History                                                                         (2)



                                     0000   100 	.SBTTL	HISTORY		; Detailed Current Edit History

                                     0000   200 ; Edit History for Version 0 of FOR$RANDOM

                                     0000   300 ;

                                     0000   400 ; 0-3	- use word offset to call for$JRAN TNH 16-SEP-77

                                     0000   500 ; 0-4	- add a bug from 11 routine to make compatible:

                                     0000   600 ;	- now tests only second parameter for 0 (first call),

                                     0000   700 ;	- instead of concatenated longword JMT 6-OCT-77

                                     0000   800 ; 0-5	- JRAN is now passed only one longword arg.  JMT 9-Oct-77

                                     0000   900 ; 0-6	- Copy back seed as 2 words or 1 long word.  TNH 14-Nov-77

                                     0000  1000 ; 0-9	- Remove FOR$JRAN which is no longer supported.

                                     0000  1100 ;	  FORTRAN compiler now generates calls to MTH$RANDOM.  JMT 4-Jan-78

                                     0000  1200 ; 0-10	- Bug fix 0-4 didn't break my code enough to be

                                     0000  1300 ;	  compatable with the 11.  JMT 16-Feb-78

                                     0000  1400 ; 0-11	- Remove FOR$FLAG_JACKET.  TNH 11-July-78

FOR$RANDOM      ; random number generator and interfaces         21-AUG-1978 18:56:24   VAX-11 MACRO X0.3-11               Page   3

0-11            DECLARATIONS                                                                                                     (3)



                                     0000   100 	.SBTTL	DECLARATIONS

                                     0000   200 

                                     0000   300 ;

                                     0000   400 ; INCLUDE FILES:

                                     0000   500 ;	oerr.mar

                                     0000   600 

                                     0000   700 ;

                                     0000   800 ; EXTERNAL SYMBOLS:

                                     0000   900 ;

                                     0000  1000 

                                     0000  1100 ;

                                     0000  1200 ; MACROS:

                                     0000  1300 ;

                                     0000  1400 

                                     0000  1500 ;

                                     0000  1600 ; PSECT DECLARATIONS:

                                 00000000  1700 	.PSECT	FOR$CODE	PIC, SHR, EXE, LONG, NOWRT

                                     0000  1800 

                                     0000  1900 ;

                                     0000  2000 ; EQUATED SYMBOLS:

                           00000004  0000  2100 	a1	=	4	; offset into AP of address of arg1

                           00000008  0000  2200 	a2	=	8	; offset into AP of address of arg2

                           0000000C  0000  2300 	a3	=	12	; (optional) offset into AP of add-

                                     0000  2400 				; ress of output

                                     0000  2500 

                                     0000  2600 ;

                                     0000  2700 ; OWN STORAGE:

                                     0000  2800 ;	NONE

FOR$RANDOM      ; random number generator and interfaces         21-AUG-1978 18:56:24   VAX-11 MACRO X0.3-11               Page   4

0-11            FOR$RANDU and FOR$RANDU_W return number as para                                                                  (4)



                                     0000   100 	.SBTTL	FOR$RANDU and FOR$RANDU_W	return number as parameter

                                     0000   200 

                                     0000   300 ;++

                                     0000   400 ; FUNCTIONAL DESCRIPTION:

                                     0000   500 ;

                                     0000   600 ;	CALLs FOR$IRAN to get a random number and returns it in

                                     0000   700 ;	third parameter.

                                     0000   800 ;

                                     0000   900 ; CALLING SEQUENCE:

                                     0000  1000 ;	CALL FOR$RANDU   (gen_base_1.ml.r, gen_base_2.ml.r,

                                     0000  1100 ;			random_fraction.wf.r)

                                     0000  1200 ;

                                     0000  1300 ;	CALL FOR$RANDU_W (gen_base_1.mw.r, gen_base_2.mw.r,

                                     0000  1400 ;			random_fraction.wf.r)

                                     0000  1500 ;

                                     0000  1600 ; INPUT PARAMETERS:

                                     0000  1700 ;	gen_base_1		seed1 for algorithm

                                     0000  1800 ;	gen_base_2		seed2 for algorithm

                                     0000  1900 ;

                                     0000  2000 ; IMPLICIT INPUTS:

                                     0000  2100 ;	NONE

                                     0000  2200 ;

                                     0000  2300 ; OUTPUT PARAMETERS:

                                     0000  2400 ;	random_fraction		floating point result is

                                     0000  2500 ;				between 0 and 1

                                     0000  2600 ;

                                     0000  2700 ; IMPLICIT OUTPUTS:

                                     0000  2800 ;	NONE

                                     0000  2900 ;

                                     0000  3000 ; COMPLETION CODES:

                                     0000  3100 ;	NONE

                                     0000  3200 ;

                                     0000  3300 ; SIDE EFFECTS:

                                     0000  3400 ;	NONE

                                     0000  3500 ;

                                     0000  3600 ;--

                                     0000  3700 

                                     0000  3800 

                                     0000  3900 

                                     0000  4000 FOR$RANDU::

                                     0000  4100 FOR$RANDU_W::

                               0000  0000  4200 	.WORD	^M<>

       000C'CF            6C     FA  0002  4400 	CALLG	(AP), W^FOR$IRAN		; R0 = floating result

         0C BC            50     50  0007  4500 	MOVF	R0, @a3(AP)		; return as third parameter

                                 04  000B  4600 	RET

FOR$RANDOM      ; random number generator and interfaces         21-AUG-1978 18:56:24   VAX-11 MACRO X0.3-11               Page   5

0-11            FOR$IRAN   result in R0                                                                                          (5)



                                     000C   100 	.SBTTL	FOR$IRAN	  result in R0

                                     000C   200 

                                     000C   300 ;++

                                     000C   400 ; FUNCTIONAL DESCRIPTION:

                                     000C   500 ;

                                     000C   600 ;	SEED = arg1,arg2

                                     000C   700 ;	if arg2 = 0 then SEED = 1	; first call only

                                     000C   800 ;	SEED = SEED * (2**16 + 3)

                                     000C   900 ;	arg1,arg2 = SEED		; return for later calls

                                     000C  1000 ;	R0 = SEED normalized to floating point

                                     000C  1100 ;

                                     000C  1200 ; CALLING SEQUENCE:

                                     000C  1300 ;	Random_fraction.wf.v = FOR$IRAN (gen_base_1.mw.r,

                                     000C  1400 ;					 gen_base_2.mw.r)

                                     000C  1500 ;

                                     000C  1600 ; INPUT PARAMETERS:

                                     000C  1700 ;	gen_base_1		seed1 for algorithm

                                     000C  1800 ;	gen_base_2		seed2 for algorithm

                                     000C  1900 ;

                                     000C  2000 ; IMPLICIT INPUTS:

                                     000C  2100 ;	NONE

                                     000C  2200 ;

                                     000C  2300 ; OUTPUT PARAMETERS:

                                     000C  2400 ;	NONE

                                     000C  2500 ;

                                     000C  2600 ; IMPLICIT OUTPUTS:

                                     000C  2700 ;	NONE

                                     000C  2800 ;

                                     000C  2900 ; COMPLETION CODES:

                                     000C  3000 ;	NONE

                                     000C  3100 ;

                                     000C  3200 ; SIDE EFFECTS:

                                     000C  3300 ;	NONE

                                     000C  3400 ;

                                     000C  3500 ; FUNCTIONAL VALUE:

                                     000C  3600 ;	A floating-point value between 0 and 1

                                     000C  3700 ;--

                                     000C  3800 

                                     000C  3900 

                                     000C  4000 

                                     000C  4100 FOR$IRAN::

                               0000  000C  4200 	.WORD	^M<>			; Use R0:R1

            50         04 BC     B0  000E  4300 	MOVW	@a1(AP), R0		; R0 = arg1

            50            10     9C  0012  4400 	ROTL	#16, R0, R0		; build a longword value

                          50         0015       

            50         08 BC     B0  0016  4500 	MOVW	@a2(AP), R0		; in R0

                                     001A  4600 					; NOTE: PDP-11 algorithm only checks

                                     001A  4700 					; bits 15:0 for 0, so VAX is compatibile

                          23     13  001A  4800 	BEQL	20$			; branch if first call

            50   00010003 8F     C5  001C  4900 	MULL3	#^X10003, R0, R1	; R1 = R0 *((2**16)+3) = SEED

                          51         0023       

            51            1F     E5  0024  5000 	BBCC	#31, R1, 15$		; make sure SEED positive

                          00         0027       

            50            51     4E  0028  5100 15$::	CVTLF	R1, R0			; R0 = floating (SEED) binary point

                                     002B  5200 					; to right of bit 0

            50   00003100 8F     44  002B  5300 	MULF	#^X3100, R0		; R0 = R0 * 2**-31 = normalized, binary point

                                     0032  5400 					; to right of bit 31

FOR$RANDOM      ; random number generator and interfaces         21-AUG-1978 18:56:24   VAX-11 MACRO X0.3-11               Page   6

0-11            FOR$IRAN   result in R0                                                                                          (5)



                                     0032  5500 					; R0 = floating point result

                                     0032  5600 					; R1 = new seed

         08 BC            51     B0  0032  5700 	MOVW	R1, @a2(AP)		; return bits 15:0 of seed

            51            10     9C  0036  5800 	ROTL	#16, R1, R1		; seed<31:16> to R1<15:0>

                          51         0039       

         04 BC            51     B0  003A  5900 	MOVW	R1, @a1(AP)		; return bits 31:16 of seed as first arg

                                 04  003E  6000 	RET				; return with R0 = floating random number

            50   00010000 8F     C0  003F  6100 20$:	ADDL	#^X10000, R0		; this is what the 11 did!

            50            03     B0  0046  6200 	MOVW	#3, R0

            51            50     D0  0049  6300 	MOVL	R0, R1

                          DA     11  004C  6400 	BRB	15$

                                     004E  6500 

                                     004E  6600 

                                     004E  6700 	.END

FOR$RANDOM      ; random number generator and interfaces         21-AUG-1978 18:56:24   VAX-11 MACRO X0.3-11               Page   7

SYMBOL TABLE                                                                                                                     (5)



A1             = 00000004            

A2             = 00000008            

A3             = 0000000C            

FOR$IRAN         0000000C RG    02   

FOR$K_ERR_PREFX= 00000018            

FOR$RANDU        00000000 RG    02   

FOR$RANDU_W      00000000 RG    02   

MTH$K_ERR_PREFX= 00000016            

MTH__FLOOVEMAT = 00000058            

MTH__FLOUNDMAT = 00000059            

MTH__INVARG    = 00000051            

MTH__LOGZERNEG = 00000053            

MTH__SINSIGLOS = 00000057            

MTH__SQUROONEG = 00000054            

MTH__UNDEXP    = 00000052            

MTH__WRONUMARG = 00000050            





PROGRAM SECTION SYNOPSIS



.  ABS  .        00000000      00     NOPIC   USR   CON   ABS   LCL NOSHR NOEXE NORD  NOWRT BYTE  

. BLANK .        00000000      01     NOPIC   USR   CON   REL   LCL NOSHR   EXE   RD    WRT BYTE  

FOR$CODE         0000004E      02       PIC   USR   CON   REL   LCL   SHR   EXE   RD  NOWRT LONG  





THERE WERE NO ERRORS OR WARNINGS.

27956. BYTES LEFT IN FREE MEMORY POOL.

OBJ$:FORRANDOM,LIS$:FORRANDOM/-SP=LIB$:S/ML,SRC$:P,FORRANDOM

0 MLB DIR RDS - 0 GETS TO DEFINE 0 MACROS. 2 INTER. FILE WRITES. 

