File: randlib.chs

package info (click to toggle)
octave2.1 1%3A2.1.73-13
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 37,028 kB
  • ctags: 20,874
  • sloc: cpp: 106,508; fortran: 46,978; ansic: 5,720; sh: 4,800; makefile: 3,186; yacc: 3,132; lex: 2,892; lisp: 1,715; perl: 778; awk: 174; exp: 134
file content (368 lines) | stat: -rw-r--r-- 13,210 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
                    SUMMARY OF ROUTINES IN RANDLIB

0. Base Level Routines to Set and Obtain Values of Seeds

(These should be the only base level routines used by  those who don't
need multiple generators with blocks of numbers.)

C**********************************************************************
C
C      SUBROUTINE SETALL(ISEED1,ISEED2)
C               SET ALL random number generators
C      INTEGER ISEED1, ISEED2
C
C**********************************************************************
C**********************************************************************
C
C     SUBROUTINE GETSD(ISEED1,ISEED2)
C               GET SeeD
C     INTEGER ISEED1, ISEED2
C
C     Returns the value of two integer seeds of the current generator
C     in ISEED1, ISEED2
C
C**********************************************************************

I. Higher Level Routines

C**********************************************************************
C
C     REAL FUNCTION GENBET( A, B )
C               GeNerate BETa random deviate
C     REAL A,B
C
C     Returns a single random deviate from the beta distribution with
C     parameters A and B.  The density of the beta is
C               x^(a-1) * (1-x)^(b-1) / B(a,b) for 0 < x < 1
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION GENCHI( DF )
C                Generate random value of CHIsquare variable
C     REAL DF
C
C     Generates random deviate from the distribution of a chisquare
C     with DF degrees of freedom random variable.
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION GENEXP( AV )
C                    GENerate EXPonential random deviate
C     REAL AV
C
C     Generates a single random deviate from an exponential
C     distribution with mean AV.
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION GENF( DFN, DFD )
C                GENerate random deviate from the F distribution
C     REAL DFN, DFD
C
C     Generates a random deviate from the F (variance ratio)
C     distribution with DFN degrees of freedom in the numerator
C     and DFD degrees of freedom in the denominator.
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION GENGAM( A, R )
C           GENerates random deviates from GAMma distribution
C     REAL A, R
C
C     Generates random deviates from the gamma distribution whose
C     density is
C          (A**R)/Gamma(R) * X**(R-1) * Exp(-A*X)
C
C**********************************************************************
C**********************************************************************
C
C     SUBROUTINE GENMN(PARM,X,WORK)
C              GENerate Multivariate Normal random deviate
C     REAL PARM(*), X(*), WORK(*)
C
C     PARM is set by SETGMN which must be called prior to GENMN.  The
C     generated deviates are placed in X.  WORK is a work array of the
C     same size as X.
C
C**********************************************************************
C**********************************************************************
C
C     SUBROUTINE GENMUL( N, P, NCAT, IX )
C              GENerate MULtinomial random deviate
C     REAL P(*)
C     INTEGER N, NCAT, IX(*)
C
C     Generates deviates from a Multinomial distribution with NCAT
C     categories.  P specifies the probability of an event in each
C     category. The generated deviates are placed in IX.
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION GENNCH( DF, XNONC )
C           Generate random value of Noncentral CHIsquare variable
C     REAL DF, XNONC
C
C     Generates random deviate  from the  distribution  of a  noncentral
C     chisquare with DF degrees  of freedom and noncentrality  parameter
C     XNONC.
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION GENNF( DFN, DFD, XNONC )
C           GENerate random deviate from the Noncentral F distribution
C     REAL DFN, DFD, XNONC
C
C     Generates a random deviate from the  noncentral F (variance ratio)
C     distribution with DFN degrees of freedom in the numerator, and DFD
C     degrees of freedom in the denominator, and noncentrality parameter
C     XNONC.
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION GENNOR( AV, SD )
C         GENerate random deviate from a NORmal distribution
C     REAL AV, SD
C
C     Generates a single random deviate from a normal distribution
C     with mean, AV, and standard deviation, SD.
C
C**********************************************************************
C**********************************************************************
C
C    SUBROUTINE GENPRM( IARRAY, LARRAY )
C               GENerate random PeRMutation of iarray
C    INTEGER IARRAY(LARRAY), LARRAY
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION GENUNF( LOW, HIGH )
C               GeNerate Uniform Real between LOW and HIGH
C     REAL LOW, HIGH
C
C**********************************************************************
C**********************************************************************
C
C     INTEGER FUNCTION IGNBIN( N, P )
C                    GENerate BINomial random deviate
C     INTEGER N
C     REAL P
C
C     Returns a single random deviate from a binomial
C     distribution whose number of trials is N and whose
C     probability of an event in each trial is P.
C
C**********************************************************************
C**********************************************************************
C
C     INTEGER FUNCTION IGNNBN( N, P )
C               GENerate Negative BiNomial random deviate
C     INTEGER N
C     REAL P
C
C     Returns a single random deviate from a negative binomial
C     distribution with number of events N and whose
C     probability of an event in each trial is P.
C
C**********************************************************************
C**********************************************************************
C
C     INTEGER FUNCTION IGNPOI( AV )
C                    GENerate POIsson random deviate
C     REAL AV
C
C     Generates a single random deviate from a Poisson
C     distribution with mean AV.
C
C**********************************************************************
C**********************************************************************
C
C     INTEGER FUNCTION IGNUIN( LOW, HIGH )
C               GeNerate Uniform INteger
C     INTEGER LOW, HIGH
C
C     Generates an integer uniformly distributed between LOW and HIGH.
C
C**********************************************************************
C**********************************************************************
C
C     SUBROUTINE PHRTSD( PHRASE, SEED1, SEED2 )
C               PHRase To SeeDs
C     CHARACTER*(*) PHRASE
C     INTEGER SEED1, SEED2
C
C     Uses a phrase (character string) to generate two seeds for the RGN
C     random number generator.
C
C**********************************************************************
C**********************************************************************
C
C     REAL FUNCTION RANF()
C                RANDom number generator as a Function
C
C     Returns a random floating point number from a uniform distribution
C     over 0 - 1 (endpoints of this interval are not returned) using the
C     current generator
C
C**********************************************************************
C**********************************************************************
C
C     SUBROUTINE SETGMN( MEANV, COVM, LDCOVM, P, PARM)
C            SET Generate Multivariate Normal random deviate
C     INTEGER LDCOVM, P
C     REAL MEANV(P), COVM(LDCOVM,P), PARM(P*(P+3)/2 + 1)
C
C     P is the length of normal vectors to be generated, MEANV
C     is the vector of their means and COVM(1:P,1:P) is their variance
C     covariance matrix.  LDCOVM is the leading actual dimension of
C     COVM, which this routine needs to know although only the
C     (1:P,1:P) slice of COVM is used.
C     Places information necessary to generate the deviates in PARM.
C
C**********************************************************************

II. Uniform Generator and Associated Routines


      A. SETTING THE SEED OF ALL GENERATORS

C**********************************************************************
C
C      SUBROUTINE SETALL(ISEED1,ISEED2)
C               SET ALL random number generators
C      INTEGER ISEED1, ISEED2
C
C**********************************************************************

      B. OBTAINING RANDOM NUMBERS

C**********************************************************************
C
C     INTEGER FUNCTION IGNLGI()
C               GeNerate LarGe Integer
C
C     Returns a random integer following a uniform distribution over
C     (1, 2147483562) using the current generator.
C
C**********************************************************************

C**********************************************************************
C
C     REAL FUNCTION RANF()
C                RANDom number generator as a Function
C
C     Returns a random floating point number from a uniform distribution
C     over 0 - 1 (endpoints of this interval are not returned) using the
C     current generator
C
C**********************************************************************

      C. SETTING AND OBTAINING THE NUMBER OF THE CURRENT GENERATOR

C**********************************************************************
C
C     SUBROUTINE SETCGN( G )
C                      Set GeNerator
C     INTEGER G
C
C     Sets  the  current  generator to G. All references to a generator
C     are to the current generator.
C
C**********************************************************************

C**********************************************************************
C
C      SUBROUTINE GETCGN(G)
C               GET Current GeNerator
C      INTEGER G
C
C      Returns in G the number of the current random number generator
C
C**********************************************************************

      D. OBTAINING OR CHANGING SEEDS IN CURRENT GENERATOR

C**********************************************************************
C
C     SUBROUTINE ADVNST(K)
C               ADV-a-N-ce ST-ate
C     INTEGER K
C
C     Advances the state  of  the current  generator  by 2^K values  and
C     resets the initial seed to that value.
C
C**********************************************************************

C**********************************************************************
C
C     SUBROUTINE GETSD(ISEED1,ISEED2)
C               GET SeeD
C     INTEGER ISEED1, ISEED2
C
C     Returns the value of two integer seeds of the current generator
C     in ISEED1, ISEED2
C
C**********************************************************************

C**********************************************************************
C
C     SUBROUTINE INITGN(ISDTYP)
C          INIT-ialize current G-e-N-erator
C
C     INTEGER ISDTYP    The state to which the generator is to be set
C          ISDTYP = -1  => sets the seeds to their initial value
C          ISDTYP =  0  => sets the seeds to the first value of
C                          the current block
C          ISDTYP =  1  => sets the seeds to the first value of
C                          the next block
C
C**********************************************************************

C**********************************************************************
C
C     SUBROUTINE SETSD(ISEED1,ISEED2)
C               SET S-ee-D of current generator
C
C     Resets the initial  seed of  the current  generator to  ISEED1 and
C     ISEED2. The seeds of the other generators remain unchanged.
C
C**********************************************************************

      E. MISCELLANY

C**********************************************************************
C
C     INTEGER FUNCTION MLTMOD(A,S,M)
C                    Returns (A*S) MOD M
C     INTEGER A, S, M
C
C**********************************************************************

C**********************************************************************
C
C      SUBROUTINE SETANT(QVALUE)
C               SET ANTithetic
C      LOGICAL QVALUE
C
C     Sets whether the current generator produces antithetic values.  If
C     X   is  the value  normally returned  from  a uniform [0,1] random
C     number generator then 1  - X is the antithetic  value. If X is the
C     value  normally  returned  from a   uniform  [0,N]  random  number
C     generator then N - 1 - X is the antithetic value.
C
C     All generators are initialized to NOT generate antithetic values.
C
C**********************************************************************