#include <stdio.h>
#include <string.h>
#define NUMBER 5000
#define ROUND
50
int main()
{
FILE *fp = NULL;
char rand_buff[NUMBER+1] = {0,};
char rand_ret = 0;
char char_arr1[2] = {'A', 'T'};
char char_arr2[2] = {'C', 'G'};
short AT_count = 0;
short CG_count = 0;
char AT_full_flag = 0;
char CG_full_flag = 0;
int i = 0, j = 0;
fp = fopen("random", "a+");
if(fp == NULL)
{
perror("fopen");
return -1;
}
srand(time(NULL));
for(i = 0; i < ROUND; i++)
{
memset(rand_buff, 0, sizeof(rand_buff));
AT_count = 0;
CG_count = 0;
AT_full_flag = 0;
CG_full_flag = 0;
for(j = 0; j < NUMBER; j++)
{
rand_ret = (rand()%10+1);
if(rand_ret <= 6)
{
if(!AT_full_flag)
{
rand_buff[j] = char_arr1[rand_ret%2];
AT_count++;
if(AT_count >= (0.6*NUMBER))
AT_full_flag = 1;
}
else
{
j--;
continue;
}
}
else
{
if(!CG_full_flag)
{
rand_buff[j] = char_arr2[rand_ret%2];
CG_count++;
if(CG_count >= (0.4*NUMBER))
CG_full_flag = 1;
}
else
{
j--;
continue;
}
}
}
rand_buff[NUMBER] = '\n';
fwrite(rand_buff, sizeof(rand_buff), 1, fp);
}
fclose(fp);
return 0;
}
[
本帖最后由 baiqtd123456 于 2013-11-22 15:21 编辑 ]