- Joined
- Apr 24, 2011
- Messages
- 1
- Reaction score
- 0
Hi Gurus,
I want to generate uniformly distributed data between 0 - Epsilon. The code is given below
Can anybody tells me that
1. Whether I am generating the data in right way?
2. The data is not correctly sorted. What is the reason.
Any help will be highly appreciated. Thanks
Regards
I want to generate uniformly distributed data between 0 - Epsilon. The code is given below
HTML:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
int compare (const void * a, const void * b)
{
return ( *(double*)a - *(double*)b );
}
int main()
{
double min = 0;
double max = DBL_EPSILON;
int dataSize = 1000;
double work[dataSize];
/* First of all generate uniformly distributed data. */
int i;
for(i = 0; i < dataSize; i++)
{
double number = (rand() * ((max - min) / RAND_MAX)) + min;
work[i] = number;
fprintf(fp, "%E \n", work[i]);
}
/* Sort the generated uniformly distributed data. */
qsort(work, dataSize, sizeof(double), compare);
/* check that data has been sorted successfully. */
for(i = 1; i <= dataSize; i++)
{
if(work[i] < work[i-1])
{
printf("Sorted data is not correct \n");
}
else
{
printf("%d \n", i);
}
}
}
Can anybody tells me that
1. Whether I am generating the data in right way?
2. The data is not correctly sorted. What is the reason.
Any help will be highly appreciated. Thanks
Regards