I have a list of team members and also 2 substitute players:
team
= Samson, Max, Rowan, Flynn, Jack
subs
= Struan, Harry
I am facing a challenge in randomly swapping the 2 subs
into the team. The difficulty lies in ensuring that only these 2 elements are swapped and that both are included in the swap. Initially, I attempted to loop through the subs
array and swap each element randomly with an element from the team
array. However, this method often resulted in scenarios where Struan was swapped with Max and then Harry was swapped with Struan, leaving Struan still in the subs
array instead of being transferred to the team
.
Therefore, my objective is to specifically exchange the 2 elements in the sub
array with random elements from the team
array. How can I accomplish this?