#define IA 48271 /* Multiplier. Best for IM s.t. no overflow in calculation. */
#define IM 2147483647  /* Modulus.  A Mersenne prime. */  
#define IQ 44488      /* (long)(IM/IA) */
#define IR 3399  /* IM%IA. For no overflow in this method must have IR<IQ. */

double rand1(long *idum)    /* Minimal random number generator.  */
                           /* Initialise with idum a pointer to */
                           /* a long. */
{
  if(*idum<0) *idum =-*idum;
  *idum=IA*(*idum%IQ)-IR*(long)(*idum/IQ);
  if (*idum<0) *idum+=IM;
  return *idum/IM;
}
