SDDSlib
Loading...
Searching...
No Matches
dlaran.c
1/*************************************************************************\
2* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3* National Laboratory.
4* Copyright (c) 2002 The Regents of the University of California, as
5* Operator of Los Alamos National Laboratory.
6* This file is distributed subject to a Software License Agreement found
7* in the file LICENSE that is included with this distribution.
8\*************************************************************************/
9
10/* dlaran.f -- translated by f2c (version of 30 January 1990 16:02:04).
11 You must link the resulting object file with the libraries:
12 -lF77 -lI77 -lm -lc (in that order)
13 $Log: not supported by cvs2svn $
14 Revision 1.7 2005/11/04 22:47:14 soliday
15 Updated code to be compiled by a 64 bit processor.
16
17 Revision 1.6 2002/08/14 16:18:54 soliday
18 Added Open License
19
20 Revision 1.5 2000/03/27 20:30:11 borland
21 Removed confusing (unnecessary) static designation for some variables.
22
23 Revision 1.4 1999/07/29 21:54:00 borland
24 Added back a file I actually need.
25
26 Revision 1.2 1995/09/05 21:19:33 saunders
27 First test release of the SDDS1.5 package.
28
29*/
30
31#include "f2c.h"
32
33doublereal dlaran_(integer *iseed) {
34 /* System generated locals */
35 doublereal ret_val;
36
37 /* Local variables */
38 integer it1, it2, it3, it4;
39
40 /* Parameter adjustments */
41 /*--iseed;*/
42
43 /* Function Body */
44
45 /* -- LAPACK auxiliary routine (version 2.0) -- */
46 /* Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
47 /* Courant Institute, Argonne National Lab, and Rice University */
48 /* February 29, 1992 */
49
50 /* .. Array Arguments .. */
51 /* .. */
52
53 /* Purpose */
54 /* ======= */
55
56 /* DLARAN returns a random real number from a uniform (0,1) */
57 /* distribution. */
58
59 /* Arguments */
60 /* ========= */
61
62 /* ISEED (input/output) INTEGER array, dimension (4) */
63 /* On entry, the seed of the random number generator; the array
64*/
65 /* elements must be between 0 and 4095, and ISEED(4) must be */
66 /* odd. */
67 /* On exit, the seed is updated. */
68
69 /* Further Details */
70 /* =============== */
71
72 /* This routine uses a multiplicative congruential method with modulus */
73
74 /* 2**48 and multiplier 33952834046453 (see G.S.Fishman, */
75 /* 'Multiplicative congruential random number generators with modulus */
76 /* 2**b: an exhaustive analysis for b = 32 and a partial analysis for */
77 /* b = 48', Math. Comp. 189, pp 331-344, 1990). */
78
79 /* 48-bit integers are stored in 4 integer array elements with 12 bits */
80
81 /* per element. Hence the routine is portable across machines with */
82 /* integers of 32 bits or more. */
83
84 /* =====================================================================
85*/
86
87 /* .. Parameters .. */
88 /* .. */
89 /* .. Local Scalars .. */
90 /* .. */
91 /* .. Intrinsic Functions .. */
92 /* .. */
93 /* .. Executable Statements .. */
94
95 /* multiply the seed by the multiplier modulo 2**48 */
96
97 it4 = iseed[3] * 2549;
98 it3 = it4 / 4096;
99 it4 -= it3 << 12;
100 it3 = it3 + iseed[2] * 2549 + iseed[3] * 2508;
101 it2 = it3 / 4096;
102 it3 -= it2 << 12;
103 it2 = it2 + iseed[1] * 2549 + iseed[2] * 2508 + iseed[3] * 322;
104 it1 = it2 / 4096;
105 it2 -= it1 << 12;
106 it1 = it1 + iseed[0] * 2549 + iseed[1] * 2508 + iseed[2] * 322 + iseed[3] * 494;
107 it1 %= 4096;
108
109 /* return updated seed */
110
111 iseed[0] = it1;
112 iseed[1] = it2;
113 iseed[2] = it3;
114 iseed[3] = it4;
115
116 /* convert 48-bit integer to a real number in the interval (0,1) */
117
118 ret_val = ((doublereal)it1 + ((doublereal)it2 + ((doublereal)it3 + (doublereal)it4 * 2.44140625e-4) * 2.44140625e-4) * 2.44140625e-4) * 2.44140625e-4;
119 return ret_val;
120
121 /* End of DLARAN */
122
123} /* dlaran_ */
124
125doublereal dlaran_oag(integer *iseed, long increment) {
126 doublereal ret_val;
127
128 integer it1, it2, it3, it4, i;
129
130 if (increment < 1)
131 increment = 1;
132 for (i = 0; i < increment; i++) {
133 it4 = iseed[3] * 2549;
134 it3 = it4 / 4096;
135 it4 -= it3 << 12;
136 it3 = it3 + iseed[2] * 2549 + iseed[3] * 2508;
137 it2 = it3 / 4096;
138 it3 -= it2 << 12;
139 it2 = it2 + iseed[1] * 2549 + iseed[2] * 2508 + iseed[3] * 322;
140 it1 = it2 / 4096;
141 it2 -= it1 << 12;
142 it1 = it1 + iseed[0] * 2549 + iseed[1] * 2508 + iseed[2] * 322 + iseed[3] * 494;
143 it1 %= 4096;
144
145 iseed[0] = it1;
146 iseed[1] = it2;
147 iseed[2] = it3;
148 iseed[3] = it4;
149 }
150
151 ret_val = ((doublereal)it1 + ((doublereal)it2 + ((doublereal)it3 + (doublereal)it4 * 2.44140625e-4) * 2.44140625e-4) * 2.44140625e-4) * 2.44140625e-4;
152 return ret_val;
153}