Advertisement

03.07.2008 at 06:24AM PST, ID: 23222867
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Reference problem [Linker error] undefined reference to 'random'

Tags: C, Dev-C++ 4.9.9.2
I have the source code for a program written in C originally for use on a Unix system. I am trying to compile it to run on a Windows XP system, but I am getting an error [Linker error] undefined reference to 'random'. I am new to this so any help would be appreciated. I have looked over some of the previous answers posted here and suspect there is a reference to a library for the 'random' function that is missing - does anyone know what library this is or another way to solve the problem? Below is the code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
/****************************************************************************
*
* Copyright (c) 2003, The Institute for Genomic Research (TIGR), Rockville,
* Maryland, U.S.A.  All rights reserved.
*
****************************************************************************/
 
#define VERYBAD 16
 
 
 
static struct stack_struct {
  int i, j, m, c;
} stack[100];
static int abi_size=16;
static unsigned abi_mask;
 
struct abi_struct {
  unsigned tag;
  int index;
} *abi_well;
struct hit_struct {
  int diff, count;
} *hit_well;
 
static condition[]={
-1, -1, -1, -1, -1, -1, -1, -1, -1,  0, /*  0-19 */
 0,  0,  0,  0,  0,  0,  0,  0,  0,  3,
 3,  3,  3,  3,  3,  3,  3,  3,  3,  3, /* 20-39 */
 3,  3,  3,  3,  3,  3,  3,  3,  3,  6,
 6,  6,  6,  6,  6,  6,  6,  6,  6,  6, /* 40-59 */
 6,  6,  6,  6,  6,  6,  6,  6,  6,  9,
 9,  9,  9,  9,  9,  9,  9,  9,  9,  9, /* 60-79 */
 9,  9,  9,  9,  9,  9,  9,  9,  9, 12,
12, 12, 12, 12, 12, 12, 12, 12, 12, 12, /* 80-99 */
12, 12, 12, 12, 12, 12, 12, 12, 12, 15};
 
static int badness[16][16]= {
/*       A   C   G   T   U   R   Y   M   W   S   K   D   H   V   B   N */
/*A*/ {  0,  3,  3,  3,  3,  1,  3,  1,  1,  3,  3,  1,  1,  1,  3,  2},
/*C*/ {  3,  0,  3,  3,  3,  3,  1,  1,  3,  1,  3,  3,  1,  1,  1,  2},
/*G*/ {  3,  3,  0,  3,  3,  1,  3,  3,  3,  1,  1,  1,  3,  1,  1,  2},
/*T*/ {  3,  3,  3,  0,  0,  3,  1,  3,  1,  3,  1,  1,  1,  3,  1,  2},
/*U*/ {  3,  3,  3,  0,  0,  3,  1,  3,  1,  3,  1,  1,  1,  3,  1,  2},
/*R*/ {  1,  3,  1,  3,  3,  1,  3,  2,  2,  2,  2,  2,  3,  2,  3,  3},
/*Y*/ {  3,  1,  3,  1,  1,  3,  1,  2,  2,  2,  2,  3,  2,  3,  2,  3},
/*M*/ {  1,  1,  3,  3,  3,  2,  2,  1,  2,  2,  3,  3,  2,  2,  3,  3},
/*W*/ {  1,  3,  3,  1,  1,  2,  2,  2,  1,  3,  2,  2,  2,  3,  3,  3},
/*S*/ {  3,  1,  1,  3,  3,  2,  2,  2,  3,  1,  2,  3,  3,  2,  2,  3},
/*K*/ {  3,  3,  1,  1,  1,  2,  2,  3,  2,  2,  1,  2,  3,  3,  2,  3},
/*D*/ {  1,  3,  1,  1,  1,  2,  3,  3,  2,  3,  2,  2,  3,  3,  3,  3},
/*H*/ {  1,  1,  3,  1,  1,  3,  2,  2,  2,  3,  3,  3,  2,  3,  3,  3},
/*V*/ {  1,  1,  1,  3,  3,  2,  3,  2,  3,  2,  3,  3,  3,  2,  3,  3},
/*B*/ {  3,  1,  1,  1,  1,  3,  2,  3,  3,  2,  2,  3,  3,  3,  2,  3},
/*N*/ {  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  3},
/*       A   C   G   T   U   R   Y   M   W   S   K   D   H   V   B   N */
};
 
static int Dlist[]={ 0, 2, 3}, Hlist[]={ 0, 1, 3};
 
int abi_code (c)
int c;
{
  register int tmp;
 
  switch (c) {
  case 0: tmp= 0; break;
  case 1: tmp= 1; break;
  case 2: tmp= 2; break;
  case 3: 
  case 4: tmp=3; break;
  case 5: tmp=random ()%2 ? 2 : 0; break;
  case 6: tmp=random ()%2 ? 3 : 1; break;
  case 7: tmp=random ()%2        ; break;
  case 8: tmp=random ()%2 ? 3 : 0; break;
  case 9: tmp=random ()%2 ? 2 : 1; break;
  case 10: tmp=random ()%2 ? 3 : 2; break;
  case 11: tmp=Dlist [random()%3]; break;
  case 12: tmp=Hlist [random()%3]; break;
  case 13: tmp=random ()%3; break;
  case 14: tmp=random ()%3+1; break;
  case 15: tmp=random ()%4; break;
  default:
    giveup ("how can other cases happen in tag_code?");
  }
  return tmp;
}
 
void abi_sort(l, r)
struct abi_struct *l, *r;
{
  register unsigned v;
  register struct abi_struct *i, *j, tmp;
 
  if (r>l) {
    v = r->tag; i = l-1; j = r;
    while (1) {
      while ((++i)->tag < v) ;
      while (j>l && (--j)->tag > v) ;
      if (i>=j) break;
      tmp = *i; *i = *j; *j = tmp;
    }
    tmp = *i; *i = *r; *r = tmp;
    abi_sort(l, i-1);
    abi_sort(i+1, r);
  }
}
 
void prepare_abi_mask()
{
  register int i;
  register unsigned acc;
 
  /* construct abi_mask */
  for (acc=i=0; i<abi_size; i++) {
    acc<<=2;
    acc|=3;
  }
  abi_mask=acc;
}
 
void abi_align(a, width, b, height, start, end)
char *a, *b;
int width, height;
int *start, *end;
{
  register int i, j, l, r, m, diff, count;
  register unsigned x;
  int left, span, abi_len, hit_len;
 
  /* construct 'a' sequence tags */
  for (x=i=0; i<abi_size-1; i++, x<<=2)
    x|=abi_code(a[i]);
  for (j=0; i<width; i++, j++, x<<=2) {
    x|=abi_code(a[i]);
    x&=abi_mask;
    abi_well[j].tag=x;
    abi_well[j].index=i;
  }
  abi_len=j;
  abi_sort(abi_well, &abi_well[abi_len-1]);
  for (i=j=0; j<abi_len; j++)
    if (abi_well[i].tag!=abi_well[j].tag)
      abi_well[++i]=abi_well[j];
  abi_len=i+1;
 
  /* construct 'b' sequence tags, and search against 'a' sequence tags */
  for (x=i=0; i<abi_size-1; i++, x<<=2)
    x|=abi_code(b[i]);
  for (count=hit_len=0; i<height; i++, x<<=2) {
    x|=abi_code(b[i]);
    x&=abi_mask;
    for (l=0, r=abi_len-1; l<=r; ) {
      m=(l+r)/2;
      if (x<abi_well[m].tag)
	r=m-1;
      else if (x>abi_well[m].tag)
	l=m+1;
      else {
	l=abi_well[m].index-i;
	for (j=0; j<hit_len; j++)
	  if (hit_well[j].diff==l) {
	    hit_well[j].count++;
	    if (hit_well[j].count>count) {
	      count=hit_well[j].count;
	      diff=hit_well[j].diff;
	      if (j) {
		hit_well[j]=hit_well[0];
		hit_well[0].count=count;
		hit_well[0].diff=diff;
	      }
	    }
	    break;
	  }
	if (j>=hit_len) {
	  hit_well[j].count=1;
	  hit_well[j].diff=l;
	  hit_len=j+1;
	}
	break;
      }
    }
  }
 
  /* calculate starting points for sequence a and b */
  if (count<=0) {
    *start=*end=0;
    return;
  } else if (diff>=0) {
    i=diff; j=0;
  } else {
    i=0; j=-diff;
  }
 
  /* find the primary alignment region first */
  for (span=0, left=x=i; i<width && j<height; i++, j++)
    if (badness[a[i]][b[j]]) {
      /*
      for (count=0, m=0, l=i+1, r=j+1; 
	   l<width && r<height && count<VERYBAD && count>condition[m];  
	   m++, l++, r++)
	if (badness[a[l]][b[r]]) count+=badness[a[l]][b[r]];
      if (l<width && r<height && count<VERYBAD)
	continue;
	*/
      if (i-x>span) {
	left=x;
	span=i-x;
      }
      x=i+1;
    }
  if (i-x>span) {
    left=x;
    span=i-x;
  }
  if (span<=0) {
    *start=*end=0;
    return;
  }
  
  /* extend alignment region toward the right, if possible */
  for (i=left+span, j=i-diff; i<width && j<height; i++, j++) 
    if (badness[a[i]][b[j]]) {
      x=0;
      stack[x].i=i+1; stack[x].j=j+1; stack[x].m=0; stack[x++].c=0;
      while (x>0) {
	for (count=stack[--x].c, m=stack[x].m, l=stack[x].i, r=stack[x].j; 
	     l<width && r<height && badness[a[l]][b[r]]==0
	       && count>condition[m];  
	     m++, l++, r++) ;
	if (l>=width || r>=height)
	  continue;
	if (count<=condition[m])
	  break;
	if ((count+=badness[a[l]][b[r]])<VERYBAD) {
	  stack[x].i=l; stack[x].j=r+1; stack[x].m=m; stack[x++].c=count;
	  stack[x].i=l+1; stack[x].j=r; stack[x].m=m+1; stack[x++].c=count;
	  stack[x].i=l+1; stack[x].j=r+1; stack[x].m=m+1; stack[x++].c=count;
	}
      }
      if (l<width && r<height && count<=condition[m])
	continue;
      x=0;
      stack[x].i=i+1; stack[x].j=j; stack[x].m=0; stack[x++].c=0;
      while (x>0) {
	for (count=stack[--x].c, m=stack[x].m, l=stack[x].i, r=stack[x].j; 
	     l<width && r<height && badness[a[l]][b[r]]==0
	       && count>condition[m];  
	     m++, l++, r++) ;
	if (l>=width || r>=height)
	  continue;
	if (count<=condition[m])
	  break;
	if ((count+=badness[a[l]][b[r]])<VERYBAD) {
	  stack[x].i=l; stack[x].j=r+1; stack[x].m=m; stack[x++].c=count;
	  stack[x].i=l+1; stack[x].j=r; stack[x].m=m+1; stack[x++].c=count;
	  stack[x].i=l+1; stack[x].j=r+1; stack[x].m=m+1; stack[x++].c=count;
	}
      }
      if (l<width && r<height && count<=condition[m]) {
	j--;
	continue;
      }
      x=0;
      stack[x].i=i; stack[x].j=j+1; stack[x].m=0; stack[x++].c=0;
      while (x>0) {
	for (count=stack[--x].c, m=stack[x].m, l=stack[x].i, r=stack[x].j; 
	     l<width && r<height && badness[a[l]][b[r]]==0
	       && count>condition[m];  
	     m++, l++, r++) ;
	if (l>=width || r>=height)
	  continue;
	if (count<=condition[m])
	  break;
	if ((count+=badness[a[l]][b[r]])<VERYBAD) {
	  stack[x].i=l; stack[x].j=r+1; stack[x].m=m; stack[x++].c=count;
	  stack[x].i=l+1; stack[x].j=r; stack[x].m=m+1; stack[x++].c=count;
	  stack[x].i=l+1; stack[x].j=r+1; stack[x].m=m+1; stack[x++].c=count;
	}
      }
      if (l<width && r<height && count<=condition[m]) {
	i--;
	continue;
      }
      break;
    }
  span=i-left;
 
  /* extend toward the left, if possible */
  for (i=left-1, j=i-diff; i>=0 && j>=0; i--, j--) 
    if (badness[a[i]][b[j]]) {
      x=0;
      stack[x].i=i-1; stack[x].j=j-1; stack[x].m=0; stack[x++].c=0;
      while (x>0) {
	for (count=stack[--x].c, m=stack[x].m, l=stack[x].i, r=stack[x].j; 
	     l>=0 && r>=0 && badness[a[l]][b[r]]==0
	       && count>condition[m];  
	     m++, l--, r--) ;
	if (l<0 || r<0)
	  continue;
	if (count<=condition[m])
	  break;
	if ((count+=badness[a[l]][b[r]])<VERYBAD) {
	  stack[x].i=l; stack[x].j=r-1; stack[x].m=m; stack[x++].c=count;
	  stack[x].i=l-1; stack[x].j=r; stack[x].m=m+1; stack[x++].c=count;
	  stack[x].i=l-1; stack[x].j=r-1; stack[x].m=m+1; stack[x++].c=count;
	}
      }
      if (l>=0 && r>=0 && count<=condition[m])
	continue;
      x=0;
      stack[x].i=i-1; stack[x].j=j; stack[x].m=0; stack[x++].c=0;
      while (x>0) {
	for (count=stack[--x].c, m=stack[x].m, l=stack[x].i, r=stack[x].j; 
	     l>=0 && r>=0 && badness[a[l]][b[r]]==0
	       && count>condition[m];  
	     m++, l--, r--) ;
	if (l<0 || r<0)
	  continue;
	if (count<=condition[m])
	  break;
	if ((count+=badness[a[l]][b[r]])<VERYBAD) {
	  stack[x].i=l; stack[x].j=r-1; stack[x].m=m; stack[x++].c=count;
	  stack[x].i=l-1; stack[x].j=r; stack[x].m=m+1; stack[x++].c=count;
	  stack[x].i=l-1; stack[x].j=r-1; stack[x].m=m+1; stack[x++].c=count;
	}
      }
      if (l>=0 && r>=0 && count<=condition[m]) {
	j++;
	continue;
      }
      x=0;
      stack[x].i=i; stack[x].j=j-1; stack[x].m=0; stack[x++].c=0;
      while (x>0) {
	for (count=stack[--x].c, m=stack[x].m, l=stack[x].i, r=stack[x].j; 
	     l>=0 && r>=0 && badness[a[l]][b[r]]==0
	       && count>condition[m];  
	     m++, l--, r--) ;
	if (l<0 || r<0)
	  continue;
	if (count<=condition[m])
	  break;
	if ((count+=badness[a[l]][b[r]])<VERYBAD) {
	  stack[x].i=l; stack[x].j=r-1; stack[x].m=m; stack[x++].c=count;
	  stack[x].i=l-1; stack[x].j=r; stack[x].m=m+1; stack[x++].c=count;
	  stack[x].i=l-1; stack[x].j=r-1; stack[x].m=m+1; stack[x++].c=count;
	}
      }
      if (l>=0 && r>=0 && count<=condition[m]) {
	i++;
	continue;
      }
      break;
    }
  span=left+span-i-1;
  left=i+1;
  
  *start=left;
  *end=left+span-1;
}
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: EvertJor
Solution Provided By: evilrix
Participating Experts: 2
Solution Grade: A
Views: 20
Translate:
Loading Advertisement...
03.07.2008 at 06:28AM PST, ID: 21070251

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.07.2008 at 06:34AM PST, ID: 21070338

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.07.2008 at 06:35AM PST, ID: 21070349

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_2_20070628