Next version of JABA
[jabaws.git] / binaries / src / fasta34 / nrandom.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: nrandom.c,v 1.2 2006/04/12 18:00:02 wrp Exp $ */
6
7 #include <stdlib.h>
8 #include <time.h>
9
10 void 
11 irand(n)        /* initialize random number generator */
12      int n;
13 {
14   if (n == 0) {
15     n = time(NULL);
16     n = n % 16381;
17     if ((n % 2)==0) n++;
18   }
19   srandom(n);
20 }
21
22 int
23 nrand(n)        /* returns a random number between 0 and n-1 where n < 2^24) */
24      int n;
25 {
26   int rn;
27
28   rn = random();
29   rn = (rn % n);
30   return rn;
31 }
32