changed reading hint
[gromacs/adressmacs.git] / src / gmxlib / rando.c
blobcc25635150c9926b830f60812658c70cad328604
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Green Red Orange Magenta Azure Cyan Skyblue
29 static char *SRCID_rando_c = "$Id$";
31 #include <time.h>
32 #include <unistd.h>
33 #include "typedefs.h"
35 int make_seed(void)
37 return (int)(((long)time(NULL)+(long)getpid()) % (long)65536);
40 real rando(int *ig)
41 /* generate a random number. */
43 int irand;
45 int m = 100000000;
46 real rm = 100000000.0; /* same number as m, but real format */
47 int m1 = 10000;
48 int mult = 31415821;
50 real r;
51 int irandh,irandl,multh,multl;
53 irand = abs(*ig) % m;
55 /* multiply irand by mult, but take into account that overflow
56 * must be discarded, and do not generate an error.
58 irandh = irand / m1;
59 irandl = irand % m1;
60 multh = mult / m1;
61 multl = mult % m1;
62 irand = ((irandh*multl+irandl*multh) % m1) * m1 + irandl*multl;
63 irand = (irand + 1) % m;
65 /* convert irand to a real random number between 0 and 1. */
66 r = (irand / 10);
67 r = r * 10 / rm;
68 if ((r <= 0) || (r > 1))
69 r = 0.0;
70 *ig = irand;
72 return r;