立即學習:https://edu.csdn.net/course/play/26755/340121?utm_source=blogtoedu
# 手工打亂 隨機交換list中的兩個值
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
import random
for i in range(100):
idx1 = random.randint(0, len(a) - 1)
idx2 = random.randint(0, len(a) - 1)
a[idx1], a[idx2] = a[idx2], a[idx1]
print(a)
# 調用函數打亂
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
random.shuffle(a)
print(a)