This procedure randomly select an element in an array and delete it so that the array size decrease until all elements are gone and the array is empty.
--
proc randDecreasArray(){
string $arr[] = {"a","b","c","d","e","f","g"};
string $nwArr[] = $arr;
int $sz = size($arr);
int $rm = $sz;
$prntArr = stringArrayToString($arr, ".");
print ($prntArr + "\n");
for ($i in $arr){
int $rnd = rand(0, $rm);
$nwArr = stringArrayRemove ({$nwArr[$rnd]},$nwArr);
$rm --;
$prnt = stringArrayToString($nwArr, ".");
print ($prnt + "\n");
}
}
randDecreasArray()
--
cheers
f.
Nessun commento:
Posta un commento