Next version of JABA
[jabaws.git] / binaries / src / fasta34 / nrand.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: nrand.c,v 1.2 2005/09/23 16:27:25 wrp Exp $ */
6
7 #include <stdlib.h>
8 #include <time.h>
9
10 int
11 irand(int n)    /* initialize random number generator */
12 {
13
14   if (n == 0) {
15     n = time(NULL);
16     n = n % 16381;
17     if ((n % 2)==0) n++;
18
19   }
20   srand(n);
21 }
22
23 int
24 nrand(int n)    /* returns a random number between 1 and n where n < 64K) */
25 {
26   int rand();
27   long rn;
28
29   rn = rand();
30 #ifdef RAND32
31   rn = rn >> 16;
32 #endif
33   rn = rn % n;
34   return (int)rn;
35 }
36
37
38
39