rand() function

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#include <windows.h>
#define T 25

char gera_seq1();

int main()
{
char AA1[T], AA2[T];
int dif_AA, grau_Desal, grau_Simi;
AA1[T] = gera_sequ1();
system("pause");
return 0;
}

char gera_sequ1()
{
int i, num;
char aa[T];
for(i = 0; i < T; i++)
{
srand(time(NULL)*i);
num = rand() % 4;
switch (num)
{
case 0:
aa[i] = 'G';
break;
case 1:
aa[i] = 'C';
break;
case 2:
aa[i] = 'A';
break;
case 3:
aa[i] = 'T';
break;
}
Sleep(2);
}
aa[T] = '\0';
printf("Sequencia 1: %s\n", aa);
return aa[T];
}

I can not use rand () function
Last edited on
I see two problems:

1) Compilation error: your declaration of gera_sequ1() is spelled incorrectly in line 10. That mean's it isn't actually declared before first use.

2) Behavioral issue with rand: You seed srand() during each iteration. You should seed once and only once in a program. Stick that at the beginning of main.
Topic archived. No new replies allowed.