xref: /csrg-svn/usr.bin/f77/libF77/random_.c (revision 47940)
1*47940Sbostic /*-
2*47940Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47940Sbostic  * All rights reserved.
418535Sralph  *
5*47940Sbostic  * %sccs.include.proprietary.c%
6*47940Sbostic  */
7*47940Sbostic 
8*47940Sbostic #ifndef lint
9*47940Sbostic static char sccsid[] = "@(#)random_.c	5.5 (Berkeley) 04/12/91";
10*47940Sbostic #endif /* not lint */
11*47940Sbostic 
12*47940Sbostic /*
1318535Sralph  * Routines to return random values
1418535Sralph  *
1518535Sralph  * calling sequence:
1618535Sralph  *	double precision d, drandm
1718535Sralph  *	i = irandm(iflag)
1818535Sralph  *	x = random(iflag)
1918535Sralph  *	d = drandm(iflag)
2018535Sralph  * where:
2118535Sralph  *	If arg is nonzero, generator is restarted and value is returned.
2218535Sralph  *	If arg is 0, next value is returned.
2318535Sralph  *	Integer values will range from 0 thru 2147483647 (see random(3)).
2418535Sralph  *	Real values will range from 0.0 thru 1.0 .
2518535Sralph  */
2618535Sralph 
2741869Sbostic #if	defined(vax) || defined(tahoe) || defined(hp300)
2818535Sralph #define	RANDMAX		2147483647
2929933Ssam #else	vax || tahoe
3018535Sralph 	UNKNOWN MACHINE!
3129933Ssam #endif	vax || tahoe
3218535Sralph 
irandm_(iarg)3318535Sralph long irandm_(iarg)
3418535Sralph long *iarg;
3518535Sralph {
3618535Sralph 	if (*iarg) srandom((int)*iarg);
3718535Sralph 	return( random() );
3818535Sralph }
3918535Sralph 
random_(iarg)4018535Sralph float random_(iarg)
4118535Sralph long *iarg;
4218535Sralph {
4318535Sralph 	if (*iarg) srandom((int)*iarg);
4418535Sralph 	return( (float)(random())/(float)RANDMAX );
4518535Sralph }
4618535Sralph 
drandm_(iarg)4718535Sralph double drandm_(iarg)
4818535Sralph long *iarg;
4918535Sralph {
5018535Sralph 	if (*iarg) srandom((int)*iarg);
5118535Sralph 	return( (double)(random())/(double)RANDMAX );
5218535Sralph }
53