Shuffle An Array Posted on 2020-11-01 22:32:44 Edited on 2020-11-01 23:36:51 Disqus: 384. Shuffle an Array 1234567891011121314151617import copyimport randomclass Solution(object): def __init__(self, nums): self.ori = copy.copy(nums) self.nums = nums def reset(self): return self.ori def shuffle(self): for i in range(len(self.nums)): pos = random.randrange(i, len(self.nums)) self.nums[i], self.nums[pos] = self.nums[pos], self.nums[i] return self.nums Post author: ToRapture Post link: https://torapture.github.io/2020/11/01/Shuffle-An-Array/ Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.