Q: Large array of random indexes 
Author Message
 Q: Large array of random indexes

I need to present an array of floating point numbers to a processing function
in a random order each time the function is called.  The array can be pretty
large (up to 20,000 elements).  The function in turn may be called tens of
thousands of times (maybe hundreds of thousands).

Currenty I use the following rand() and modulus routine to randomize
a set of indices from 0 to n.

void shuffle(int Maxneeded, int randindex[]){
int i,x;
    for(i=0; i < Maxneeded; i++) randindex[i] = -1;
    for(i=0; i < Maxneeded; i++){
        x = rand() % Maxneeded;
        while(randindex[x] !=-1){
            x++;
            x = x % Maxneeded;
        }
        randindex[x]=i;
    }

Quote:
} /* end shuffle */

While it works, it is terribly slow - too slow.  On the other hand, qsort
when used to sort the same size random array is much, much faster.

Is there a way that I can use qsort to sort an array and have an index
follow the sorted number, similar to the following?

Given the following:
x = list of sequential numbers from 0 to n
y = n random numbers
        x     y
      ------------
     |  0  | rand |
     |  1  | rand |
     |  2  | rand |
     |  3  | rand |
     |  4  | rand |
     |  5  | rand |
     | ... | .... |
     |  n  | rand |
      ------------

Sort based on y (taking the associated x with the sorted y) and then use x
as a source of randomized indexes.

Any help is apreciated.  I checked the faq and old news group postings
(all that had not expired), but could find no reference to this particular
problem.




Mon, 23 Dec 1996 04:36:41 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. PFW4.5 primary / sec index Qs

2. Help with Dynamic Array/Random Access Files

3. Random Access Files & Arrays

4. Creating an array of unique random numbers

5. drop and recreate index vs large insert with index

6. indexing a large, non-indexed table

7. Random order index field selection

8. Large array mapping

9. Large Arrays

10. Storing very large numeric arrays in the database (OLE OBJECT Data Type)

11. storing/retrieving large doube[] arrays

12. Storing a very large array in Access Database


 
Powered by phpBB® Forum Software