Hi List, I need a function which randomly takes a subarray of n elements from a given array (where each element of the input array can only be once in the subarray).
So: Function GetSubSet(arr Array of Const; n integer): array of const; I need it to get a random subset of numbers (of length n) from a given set of numbers, so inserting an array like (1,2,3,4,5,6,7) with n=3 should retrieve something like (2, 5, 7). I wonder what would be the most efficient approach for this, in terms of CPU and memory use. Of course I can just make a while loop, where a random element is each time picked from the input array, but when this element is allready in the output array from a previous turn of the loop, this needs to be repeated. Maybe this can be quite time consuming for very big arrays when requesting a big result array?? Furthermore, I wondered if this would be more efficient to do it with a TList in stead of with arrays? Anyone any ideas?? Thanks, Rinke _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

