class_docstr: 随机顺序的 Sampler 。
  
  :param dataset: 实现了 __len__ 方法的数据容器
  :param shuffle: 是否在每次 iterate 的时候打乱顺序
  :param seed: 随机数种子
  :param kwargs: fastNLP 内部使用的参数
class_docstr_tok: ["\u968f\u673a\u987a\u5e8f\u7684","Sampler","\u3002",":","param","dataset",":","\u5b9e\u73b0\u4e86","__len__","\u65b9\u6cd5\u7684\u6570\u636e\u5bb9\u5668",":","param","shuffle",":","\u662f\u5426\u5728\u6bcf\u6b21","iterate","\u7684\u65f6\u5019\u6253\u4e71\u987a\u5e8f",":","param","seed",":","\u968f\u673a\u6570\u79cd\u5b50",":","param","kwargs",":","fastNLP","\u5185\u90e8\u4f7f\u7528\u7684\u53c2\u6570"]
docstr: 当前使用 num_consumed_samples 做法会在交替使用的时候遇到问题。
  
  Example::
  
      >>> sampler = RandomSampler()
      >>> iter1 = iter(sampler)
      >>> iter2 = iter(sampler)
      >>> next(iter1)
      >>> next(iter2)  # 当前num_consumed_samples的数量会发生变化
docstr_tok: ["\u5f53\u524d\u4f7f\u7528","num_consumed_samples","\u505a\u6cd5\u4f1a\u5728\u4ea4\u66ff\u4f7f\u7528\u7684\u65f6\u5019\u9047\u5230\u95ee\u9898\u3002","Example",":",":",">",">",">","sampler","=","RandomSampler","(",")",">",">",">","iter1","=","iter","(","sampler",")",">",">",">","iter2","=","iter","(","sampler",")",">",">",">","next","(","iter1",")",">",">",">","next","(","iter2",")","#","\u5f53\u524dnum_consumed_samples\u7684\u6570\u91cf\u4f1a\u53d1\u751f\u53d8\u5316"]
code: def __iter__(self):
      r"""
      当前使用 num_consumed_samples 做法会在交替使用的时候遇到问题。
  
      Example::
  
          >>> sampler = RandomSampler()
          >>> iter1 = iter(sampler)
          >>> iter2 = iter(sampler)
          >>> next(iter1)
          >>> next(iter2)  # 当前num_consumed_samples的数量会发生变化
      """
  
      if self.during_iter:  # 如果发现_during_iter为True，说明之前的还没结束，只有强制重新初始化了
          self.num_consumed_samples = 0
      self.during_iter = True
      indices = self.generate_indices()
  
      if self.pad:
          # add extra samples to make it evenly divisible
          padding_size = self.total_size - len(indices)
          if padding_size <= len(indices):
              indices += indices[:padding_size]
          else:
              indices += (
                  indices * math.ceil(padding_size / len(indices))
              )[:padding_size]
      else:
          # remove tail of data to make it evenly divisible.
          indices = indices[: self.total_size]
  
      assert len(indices) == self.total_size
  
      # subsample
      indices = indices[self.num_consumed_samples :]
      indices = indices[self.rank : len(indices) : self.num_replicas]
      assert len(indices) == self.num_left_samples
      for idx, index in enumerate(indices, start=1):
          self.num_consumed_samples += self.num_replicas
          yield index
      self.during_iter = False
      self.num_consumed_samples = 0
  
imports: from typing import Dict, List, Union, Sequence
  import math
  import numpy
  from fastNLP.core.log import logger
  from fastNLP.core.dataset import DataSet
label_desc: Use image node_id 3 for calling the RandomSampler obj's underlying member method code with example usage: obj.__iter__() without return types