Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
time_t time_start, time_end, time_period;
time_start = time(0);
//time_start = time(NULL);
FILE *fPtr;
if ((fPtr = fopen("basePair_125kb.bin", "wb+")) == NULL)
{
printf("File could not be opened.\n");
return -1;
}
srand(time(NULL));
unsigned long basePair_0, basePair_1, basePair_2, basePair_32bit;
int loop;
for (loop = 0; loop < 7812; loop++)
{
basePair_0 = rand();
basePair_1 = rand();
basePair_2 = rand();
basePair_32bit = (basePair_2 << 30) + (basePair_1 << 15) + basePair_0;
fprintf(fPtr, "%.8X", basePair_32bit);
if (loop % 1000 == 0)
{
printf("loop count = %d\n", loop);
}
}
basePair_0 = rand();
basePair_1 = rand();
basePair_2 = rand();
basePair_32bit = (basePair_2 << 30) + (basePair_1 << 15) + basePair_0;
basePair_32bit = basePair_32bit >> 16;
printf("Random 15-bit basePair_0: %u\n", basePair_0);
printf("Random 15-bit basePair_1: %u\n", basePair_1);
printf("Random 2-bit basePair_2: %u\n", basePair_2);
printf("Random 32-bit basePair_32bit: %u\n", basePair_32bit);
printf("RAND_MAX = %u\n", RAND_MAX);
printf("sizeof(long) = %d\n", sizeof(long));
fprintf(fPtr, "%.4X", basePair_32bit);
fclose(fPtr);
time_end = time(0);
//time_end = time(NULL);
time_period = time_end - time_start;
printf("Time to run the random DNA generation = %d\n", time_period);
return 0;
}
hi guys.... afta consult our lecturer, we successfully done few parts of our assignment... somehow, we do not know how to convert it from hexadecimal form to binary form and finally to character form (ATGC)... anyone can suggest us how to convert?