/* Nucleotide Sequence Generator - seq-gen, version 1.2.5 */ /* (c) Copyright 1996-2001, Andrew Rambaut & Nick Grassly */ /* Department of Zoology, University of Oxford */ /****************************************************************************** The following code comes from tools.c in Yang's PAML package U(0,1): AS 183: Appl. Stat. 31:188-190 Wichmann BA & Hill ID. 1982. An efficient and portable pseudo-random number generator. Appl. Stat. 31:188-190 x, y, z are any numbers in the range 1-30000. Integer operation up to 30323 required. ******************************************************************************/ #include #include #include "random.h" static int z_rndu=137; static unsigned w_rndu=13757; void SetSeed (int seed) { z_rndu = 170*(seed%178) + 137; w_rndu=seed; } #ifdef FAST_RANDOM_NUMBER double rndu (void) { w_rndu *= 127773; return ldexp((double)w_rndu, -32); } #else double rndu (void) { static int x_rndu=11, y_rndu=23; double r; x_rndu = 171*(x_rndu%177) - 2*(x_rndu/177); y_rndu = 172*(y_rndu%176) - 35*(y_rndu/176); z_rndu = 170*(z_rndu%178) - 63*(z_rndu/178); if (x_rndu<0) x_rndu+=30269; if (y_rndu<0) y_rndu+=30307; if (z_rndu<0) z_rndu+=30323; r = x_rndu/30269.0 + y_rndu/30307.0 + z_rndu/30323.0; return (r-(int)r); } #endif