# RandomSampler Source: https://www.tensorplay.cn/docs/generated/tensorplay.utils.data.RandomSampler.html ```python class tensorplay.utils.data.RandomSampler(data_source: Sized, replacement: bool = False, num_samples: int | None = None, generator: Generator | None = None) ``` Samples elements randomly. If without replacement, then sample from a shuffled dataset. If with replacement, then user can specify num_samples to draw. Parameters: - data_source (Sized) – data source to sample from. Must implement __len__. - replacement ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – samples are drawn on-demand with replacement if True, default=``False``. - num_samples ([int](https://docs.python.org/3/builtins/functions.html#int)) – number of samples to draw, default=`len(dataset)`. - generator ([Generator](/docs/generated/tensorplay.Generator.html#tensorplay.Generator)) – Generator used in sampling.