Next version of JABA
[jabaws.git] / binaries / src / fasta34 / nrand48.c
1
2 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
3    U. of Virginia */
4
5 /* $Name: fa_34_26_5 $ - $Id: nrand48.c,v 1.4 2006/04/12 18:00:02 wrp Exp $ */
6
7 #include <stdlib.h>
8 #include <time.h>
9
10 void 
11 irand(int n)    /* initialize random number generator */
12 {
13   if (n == 0) {
14     n = time(NULL);
15     n = n % 16381;
16     if ((n % 2)==0) n++;
17   }
18   srand48(n);
19 }
20
21 int
22 nrand(int n)    /* returns a random number between 0 and n-1 where n < 64K) */
23 {
24   int rn;
25
26   rn = lrand48();
27   rn = rn >> 16;
28   rn = (rn % n);
29   return rn;
30 }
31