xref: /original-bsd/usr.bin/f77/libF77/random_.c (revision 241757c4)
1 /*
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.
5  *
6  *	@(#)random_.c	5.3	10/30/86
7  *
8  * Routines to return random values
9  *
10  * calling sequence:
11  *	double precision d, drandm
12  *	i = irandm(iflag)
13  *	x = random(iflag)
14  *	d = drandm(iflag)
15  * where:
16  *	If arg is nonzero, generator is restarted and value is returned.
17  *	If arg is 0, next value is returned.
18  *	Integer values will range from 0 thru 2147483647 (see random(3)).
19  *	Real values will range from 0.0 thru 1.0 .
20  */
21 
22 #if	defined(vax) || defined(tahoe)
23 #define	RANDMAX		2147483647
24 #else	vax || tahoe
25 	UNKNOWN MACHINE!
26 #endif	vax || tahoe
27 
28 long irandm_(iarg)
29 long *iarg;
30 {
31 	if (*iarg) srandom((int)*iarg);
32 	return( random() );
33 }
34 
35 float random_(iarg)
36 long *iarg;
37 {
38 	if (*iarg) srandom((int)*iarg);
39 	return( (float)(random())/(float)RANDMAX );
40 }
41 
42 double drandm_(iarg)
43 long *iarg;
44 {
45 	if (*iarg) srandom((int)*iarg);
46 	return( (double)(random())/(double)RANDMAX );
47 }
48