class_docstr: Samples elements randomly. If without replacement, then sample from a shuffled dataset.
  If with replacement, then user can specify :attr:`num_samples` to draw.
  
  Args:
      data_source (Dataset): dataset to sample from
      replacement (bool): samples are drawn on-demand with replacement if ``True``, default=``False``
      num_samples (int): number of samples to draw, default=`len(dataset)`. This argument
          is supposed to be specified only when `replacement` is ``True``.
      generator (Generator): Generator used in sampling.
class_docstr_tok: ["Samples","elements","randomly",".","If","without","replacement",",","then","sample","from","a","shuffled","dataset",".","If","with","replacement",",","then","user","can","specify",":","attr",":","`","num_samples","`","to","draw",".","Args",":","data_source","(","Dataset",")",":","dataset","to","sample","from","replacement","(","bool",")",":","samples","are","drawn","on-demand","with","replacement","if","``","True","``",",","default=","``","False","``","num_samples","(","int",")",":","number","of","samples","to","draw",",","default=","`","len","(","dataset",")","`",".","This","argument","is","supposed","to","be","specified","only","when","`","replacement","`","is","``","True","``",".","generator","(","Generator",")",":","Generator","used","in","sampling","."]
code: def __init__(
      self,
      data_source,
      replacement=False,
      num_samples=None,
      generator=None,
  ):
      self.data_source = data_source
      self.replacement = replacement
      self._num_samples = num_samples
      self.generator = generator
  
      if not isinstance(self.replacement, bool):
          raise ValueError(
              "replacement should be a boolean value, but got "
              f"replacement={self.replacement}"
          )
  
      if self._num_samples is not None and not replacement:
          raise ValueError(
              "With replacement=False, num_samples should not be specified, "
              "since a random permute will be performed."
          )
  
      if not isinstance(self.num_samples, int) or self.num_samples <= 0:
          raise ValueError(
              "num_samples should be a positive integer "
              f"value, but got num_samples={self.num_samples}"
          )
  
imports: from typing import Iterator, Optional, Sized, Sequence
  import math
  from ....utils import require_not_none
label_desc: Use image node_id 1 to create a new RandomSampler object from inherited base classes: Sampler with example: obj = RandomSampler(data_source, replacement, num_samples, generator)