Problem in generating uniform distribution between 0 - Epsilon

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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top