From a list like
test = {{1, 3}, {2,7, 8}, {5,6}};
I would like to randomly select k
elements, lift them out of their current sublist and place them into a different random sublist and sort the sublist.
Desired output should look like:
RandomSwap[test]
{{1}, {2,7}, {3,5,6,8}};
RandomSwap[test]
{{1,7}, {2,6}, {3,5,8}};
I can get the indexes of the elements I need to swap by doing (if I'm looking for 2 elements in this tiny example)
k =2
ListIndexes = RandomSample[Range[Length[test]], k]
Then select a random number of entries in each sub list
ElementsIndexes = Flatten[RandomSample[#, 1] & /@ Range[Map[Length, child[[MutationIndexes]]]]]
But I don't know how to perform the swaps in an efficient/vectorized way.