GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ignuin.f
Go to the documentation of this file.
1  INTEGER FUNCTION ignuin(low,high)
2 C**********************************************************************
3 C
4 C INTEGER FUNCTION IGNUIN( LOW, HIGH )
5 C
6 C GeNerate Uniform INteger
7 C
8 C
9 C Function
10 C
11 C
12 C Generates an integer uniformly distributed between LOW and HIGH.
13 C
14 C
15 C Arguments
16 C
17 C
18 C LOW --> Low bound (inclusive) on integer value to be generated
19 C INTEGER LOW
20 C
21 C HIGH --> High bound (inclusive) on integer value to be generated
22 C INTEGER HIGH
23 C
24 C
25 C Note
26 C
27 C
28 C If (HIGH-LOW) > 2,147,483,561 prints error message on * unit and
29 C stops the program.
30 C
31 C**********************************************************************
32 
33 C IGNLGI generates integers between 1 and 2147483562
34 C MAXNUM is 1 less than maximum generable value
35 C .. Parameters ..
36  INTEGER maxnum
37  parameter(maxnum=2147483561)
38  CHARACTER*(*) err1,err2
39  parameter(err1='LOW > HIGH in IGNUIN',
40  + err2=' ( HIGH - LOW ) > 2,147,483,561 in IGNUIN')
41 C ..
42 C .. Scalar Arguments ..
43  INTEGER high,low
44 C ..
45 C .. Local Scalars ..
46  INTEGER err,ign,maxnow,range,ranp1
47 C ..
48 C .. External Functions ..
49  INTEGER ignlgi
50  EXTERNAL ignlgi
51 C ..
52 C .. Intrinsic Functions ..
53  INTRINSIC mod
54 C ..
55 C .. Executable Statements ..
56  IF (.NOT. (low.GT.high)) go to 10
57  err = 1
58 C ABORT-PROGRAM
59  go to 80
60 
61  10 range = high - low
62  IF (.NOT. (range.GT.maxnum)) go to 20
63  err = 2
64 C ABORT-PROGRAM
65  go to 80
66 
67  20 IF (.NOT. (low.EQ.high)) go to 30
68  ignuin = low
69  RETURN
70 
71 C Number to be generated should be in range 0..RANGE
72 C Set MAXNOW so that the number of integers in 0..MAXNOW is an
73 C integral multiple of the number in 0..RANGE
74 
75  30 ranp1 = range + 1
76  maxnow = (maxnum/ranp1)*ranp1
77  40 ign = ignlgi() - 1
78  IF (.NOT. (ign.LE.maxnow)) go to 40
79  ignuin = low + mod(ign,ranp1)
80  RETURN
81 
82  80 IF (.NOT. (err.EQ.1)) go to 90
83  WRITE (*,*) err1
84  go to 100
85 
86 C TO ABORT-PROGRAM
87  90 WRITE (*,*) err2
88  100 WRITE (*,*) ' LOW: ',low,' HIGH: ',high
89  WRITE (*,*) ' Abort on Fatal ERROR'
90  IF (.NOT. (err.EQ.1)) go to 110
91  CALL xstopx('LOW > HIGH in IGNUIN')
92 
93  110 CALL xstopx(' ( HIGH - LOW ) > 2,147,483,561 in IGNUIN')
94 
95  120 END
octave_int< T > mod(const octave_int< T > &x, const octave_int< T > &y)
Definition: oct-inttypes.h:959