Dear Group,
I'm in need of a function, which is called with one argument, a list.
The function is to chose one element of the list randomly, AND modify
the original list by removing the chosen element from it. My problem is
that I cannot modify the global variable from inside the function. It
is not a solution to return with a list such as:
Return[{chosen_element, modified_local_list}], and than make an
assignment outside the function.
I'm thinking on some call-by-reference method, but as I've learned so
far, there is no user-friendly way to do this, just some workarounds
(which I don't know). Any suggestions?
Istvan
example code below:
RandomChoseElem[list_List] := Module[
{pos, elem},
pos = Random[Integer, {1, Length[list]}];
elem = list[[pos]];
(* This is to be solved inside : *)
(* global`list = Drop[global`list, {pos}]; *)
Return[elem]
];
set = {1, 2, 3, 4};
RandomChoseElem[set]