from torch.utils.data.sampler import WeightedRandomSampler
print(list(WeightedRandomSampler([0.4, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], 60, replacement=True)))
# [3, 2, 0, 6, 6, 4, 0, 3, 2, 0, 0, 0, 0, 3, 0, 2, 7, 7, 6, 0, 6, 1, 4, 0, 0, 0, 6, 5, 4, 5, 0, 3, 7, 4, 7, 0, 2, 6, 5, 0, 0, 0, 0, 4, 3, 3, 3, 2, 0, 7, 1, 5, 3, 5, 2, 4, 1, 2, 3, 6]
replcement就是可以继续使用原来的。