/*Translated by FOR_C, v3.4.2 (-), on 07/09/115 at 08:31:56 */
/*FOR_C Options SET: ftn=u io=c no=p op=aimnv s=dbov str=l x=f - prototypes */
#include <math.h>
#include "fcrt.h"
#include "dranr.h"
#include <stdlib.h>
		/* PARAMETER translations */
#define	M	97
#define	MTWO	(-2.0e0)
		/* end of PARAMETER translations */
 
	/* COMMON translations */
struct t_rancd2 {
	double dnums[M];
	}	rancd2;
struct t_rancd1 {
	long int dptr;
	LOGICAL32 dgflag;
	}	rancd1;
	/* end of COMMON translations */
double /*FUNCTION*/ dranr(
double alpha)
{
	double dranr_v;
	static LOGICAL32 first = TRUE;
		/* OFFSET Vectors w/subscript range: 1 to dimension */
	double *const Dnums = &rancd2.dnums[0] - 1;
		/* end of OFFSET VECTORS */
 
	/* Copyright (c) 1996 California Institute of Technology, Pasadena, CA.
	 * ALL RIGHTS RESERVED.
	 * Based on Government Sponsored Research NAS7-03001.
	 *>> 1994-10-20 DRANR Krogh  Changes to use M77CON
	 *>> 1994-06-24 DRANR CLL Changed common to use RANC[D/S]1 & RANC[D/S]2.
	 *>> 1992-03-16 CLL
	 *>> 1991-11-26 CLL Reorganized common. Using RANCM[A/D/S].
	 *>> 1991-11-22 CLL Added call to RAN0, and DGFLAG in common.
	 *>> 1991-01-15 CLL Reordered common contents for efficiency.
	 *>> 1990-01-23 CLL  Making names in common same in all subprogams.
	 *>> 1987-04-22 DRANR  Lawson  Initial code.
	 *        Returns one pseudorandom number from the Rayleigh distribution
	 *     with parameter, ALPHA, which should be positive.
	 *     If U is random, uniform on [0, 1], the Rayleigh variable is given
	 *     by                   DRANR = ALPHA * sqrt(-2.0 * log(U))
	 *     This variable has    mean = ALPHA * sqrt(Pi/2)
	 *     and                  variance = (2 - Pi/2) * ALPHA**2
	 *     Code based on subprogram written for JPL by Stephen L. Ritchie,
	 *     Heliodyne Corp. and Wiley R. Bunton, JPL, 1969.
	 *     Adapted to Fortran 77 for the JPL MATH77 library by C. L. Lawson &
	 *     S. Y. Chiu, JPL, Apr 1987.
	 *     ------------------------------------------------------------------
	 *--D replaces "?": ?RANR, ?RANUA, RANC?1, RANC?2, ?PTR, ?NUMS, ?GFLAG
	 *     RANCD1 and RANCD2 are common blocks.
	 *     Calls RAN0 to initialize DPTR and DGFLAG.
	 *     ------------------------------------------------------------------ */
	/*     ------------------------------------------------------------------ */
	if (first)
	{
		first = FALSE;
		ran0();
	}
 
	rancd1.dptr -= 1;
	if (rancd1.dptr == 0)
	{
		dranua( rancd2.dnums, M );
		rancd1.dptr = M;
	}
	dranr_v = alpha*sqrt( MTWO*log( Dnums[rancd1.dptr] ) );
	return( dranr_v );
} /* end of function */