L
lallous
Hello,
This code works fine when 'size' is less than 32768 however when size is
bigger this function never returns.
Can't find out why?!
If I break into the code I can see that 'i' is 32768....
void MakeRandomArray(unsigned long **a, unsigned long size)
{
unsigned long *data = new unsigned long [size];
double sizef = (double)(size - 1);
char *map = new char[size];
unsigned long n, i;
memset(data, 0, size * sizeof(unsigned long));
memset(map, 0, size * sizeof(char));
srand((unsigned) time(NULL));
for (i=0;i<size;i++)
{
for (;
{
double f = ((double) rand()) / RAND_MAX;
n = (unsigned long)(f * sizef);
if (map[n])
continue;
data = n;
map[n] = 1;
break;
}
}
delete [] map;
*a = data;
}
This code works fine when 'size' is less than 32768 however when size is
bigger this function never returns.
Can't find out why?!
If I break into the code I can see that 'i' is 32768....
void MakeRandomArray(unsigned long **a, unsigned long size)
{
unsigned long *data = new unsigned long [size];
double sizef = (double)(size - 1);
char *map = new char[size];
unsigned long n, i;
memset(data, 0, size * sizeof(unsigned long));
memset(map, 0, size * sizeof(char));
srand((unsigned) time(NULL));
for (i=0;i<size;i++)
{
for (;
{
double f = ((double) rand()) / RAND_MAX;
n = (unsigned long)(f * sizef);
if (map[n])
continue;
data = n;
map[n] = 1;
break;
}
}
delete [] map;
*a = data;
}