aboutsummaryrefslogtreecommitdiff
path: root/math/slalib/random.F__vms
blob: b57b5fc91b22e9e8a92c58a2658cf20d1a08e8a7 (plain) (blame)
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
REAL FUNCTION sla_RANDOM (SEED)
*+
*     - - - - - - -
*      R A N D O M
*     - - - - - - -
*
*  Generate pseudo-random real number in the range 0 <= X < 1.
*  (single precision)
*
*  !!!  Version for VAX/VMS and DECstation !!!
*
*  Given:
*     SEED     real     an arbitrary real number
*
*  Notes:
*
*  1)  The result is a pseudo-random REAL number in the range
*      0 <= sla_RANDOM < 1.
*
*  2)  SEED is used first time through only.
*
*  Called:  RAN (a REAL function from the DEC Fortran Library)
*
*  P.T.Wallace   Starlink   14 October 1991
*
*  License:
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program (see SLA_CONDITIONS); if not, write to the 
*    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
*    Boston, MA  02110-1301  USA
*
*-

      IMPLICIT NONE

      REAL SEED

      REAL RAN

      REAL AS
      INTEGER ISEED
      LOGICAL FIRST
      SAVE FIRST
      DATA FIRST /.TRUE./



*  If first time, turn SEED into a large, odd integer
      IF (FIRST) THEN
         AS=ABS(SEED)+1.0
         ISEED=NINT(AS/10.0**(NINT(ALOG10(AS))-6))
         IF (MOD(ISEED,2).EQ.0) ISEED=ISEED+1
         FIRST=.FALSE.
      END IF

*  Next pseudo-random number
      sla_RANDOM=RAN(ISEED)

      END