On 20 Oct 2005 at 11:09, Malcolm Clark wrote:

>  >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).
> 
> 
> One good idea which someone on this list suggested some time ago was to 
> swap the element that you have just found (by random (x), where x 
> indicates the number of elements in a zero-based array) with the last 
> element in the arraray and reduce x by one for the next time. This 
> changes the order of input data of course. Example code below.

Hi Malcolm, 

Great, very smart. That was exactly what I was looking for. Very smart to swap 
the 
already placed elements to the back of the array.

I don't think the order of the input data is changed, because delphi makes a 
local copy 
of any open array parameter passed into a function. So the original input data 
is not 
changed. The requested array is not ordened of course, but that's no problem in 
my 
case.

Thanks, Rinke


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to