I am implementing a shuffling algorithm and I need to check how many times I have ti run the algorithm to get the original array. I have tried implementing a while loop and initiating a counter but there is some problem with the scope. The arrays arr and arr2 have equal values. Can someone help?
from random import randint, random
from math import floor
def shuffle(the_list):
amnt_to_shuffle = len(the_list)
while amnt_to_shuffle > 1:
i = int(floor(random() * amnt_to_shuffle))
amnt_to_shuffle -= 1
the_list[i], the_list[amnt_to_shuffle] = the_list[amnt_to_shuffle], the_list[i]
return the_list
arr = [i for i in range(1,11)]
original_arr = arr
k = 0
while 1:
arr2 = shuffle(arr)
if arr2 == original_arr:
break
else:
shuffle(arr)
k += 1
print(k)