BSD 4_3_Reno release
[unix-history] / usr / src / lib / libF77 / rand_.c
CommitLineData
d8f9b501 1/*
be6e3ddf
RE
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
d8f9b501 5 *
1c15e888 6 * @(#)rand_.c 5.4 5/13/90
eda8efe9 7 *
d8f9b501
DW
8 * Routines to return random values
9 *
10 * calling sequence:
11 * double precision d, drand
12 * i = irand(iflag)
13 * x = rand(iflag)
14 * d = drand(iflag)
15 * where:
16 * If arg is 1, generator is restarted. If arg is 0, next value
17 * is returned. Any other arg is a new seed for the generator.
18 * Integer values will range from 0 thru 2147483647.
19 * Real values will range from 0.0 thru 1.0
20 * (see rand(3))
21 */
22
02188c47 23#if defined(vax) || defined(tahoe) || defined(hp300)
d8f9b501 24#define RANDMAX 2147483647
d008ac38 25#else vax || tahoe
d8f9b501
DW
26#if pdp11
27#define RANDMAX 32767
28#else pdp11
29 UNKNOWN MACHINE!
30#endif pdp11
d008ac38 31#endif vax || tahoe
d8f9b501
DW
32
33long irand_(iarg)
34long *iarg;
35{
36 if (*iarg) srand((int)*iarg);
37#if pdp11
38 return(( ((long)rand()) << 16) | rand());
39#else pdp11
40 return( rand() );
41#endif pdp11
42}
43
44float rand_(iarg)
45long *iarg;
46{
47 if (*iarg) srand((int)*iarg);
48 return( (float)(rand())/(float)RANDMAX );
49}
50
51double drand_(iarg)
52long *iarg;
53{
54 if (*iarg) srand((int)*iarg);
55 return( (double)(rand())/(double)RANDMAX );
56}