import random
class Solution:
def __init__(self, nums: List[int]):
self.nums = nums
self.origin = list(nums) #存储原始数组备用
def reset(self) -> List[int]:
self.nums = list(self.origin) #直接拿原始数组
return self.nums
def shuffle(self) -> List[int]:
shuffle = [0] * len(self.nums) #洗牌数组
# 每次从0 ~ len(nums)-1个位置中选一个数字弹出,放入洗牌数组
for i in range(len(self.nums)):
j = random.randrange(len(self.nums))
shuffle[i] = self.nums.pop(j)
self.nums = shuffle
return self.nums