xref: /original-bsd/usr.bin/f77/libF77/rand_.c (revision e59fb703)
1 /*-
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)rand_.c	5.5 (Berkeley) 04/12/91";
10 #endif /* not lint */
11 
12 /*
13  * Routines to return random values
14  *
15  * calling sequence:
16  *	double precision d, drand
17  *	i = irand(iflag)
18  *	x = rand(iflag)
19  *	d = drand(iflag)
20  * where:
21  *	If arg is 1, generator is restarted. If arg is 0, next value
22  *	is returned. Any other arg is a new seed for the generator.
23  *	Integer values will range from 0 thru 2147483647.
24  *	Real values will range from 0.0 thru 1.0
25  *	(see rand(3))
26  */
27 
28 #if	defined(vax) || defined(tahoe) || defined(hp300)
29 #define	RANDMAX		2147483647
30 #else	vax || tahoe
31 #if	pdp11
32 #define	RANDMAX		32767
33 #else	pdp11
34 	UNKNOWN MACHINE!
35 #endif	pdp11
36 #endif	vax || tahoe
37 
38 long irand_(iarg)
39 long *iarg;
40 {
41 	if (*iarg) srand((int)*iarg);
42 #if	pdp11
43 	return(( ((long)rand()) << 16) | rand());
44 #else	pdp11
45 	return( rand() );
46 #endif	pdp11
47 }
48 
49 float rand_(iarg)
50 long *iarg;
51 {
52 	if (*iarg) srand((int)*iarg);
53 	return( (float)(rand())/(float)RANDMAX );
54 }
55 
56 double drand_(iarg)
57 long *iarg;
58 {
59 	if (*iarg) srand((int)*iarg);
60 	return( (double)(rand())/(double)RANDMAX );
61 }
62