I'm trying to randomly swap two indexes in a list and then append that list to another list. I wrote the following code:
import random
def swap(arr):
for i in range(len(arr)):
y = random.randrange(0,len(arr))
temp = arr[i]
arr[i] = arr[y]
arr[y] = temp
return arr
Array = [0,1,2,3]
results = []
for i in range(10):
a = []
a = swap(Array)
results.append(a)
print(results)
The array is getting shuffled every time, but when I print out results at the end, every index is the same ordering of the last array appended to it. For example after one run through results was: [[0, 2, 1, 3], [0, 2, 1, 3], [0, 2, 1, 3], [0, 2, 1, 3], [0, 2, 1, 3], [0, 2, 1, 3], [0, 2, 1, 3], [0, 2, 1, 3], [0, 2, 1, 3], [0, 2, 1, 3]]