# RandomSampler

Source: https://www.tensorplay.cn/docs/generated/tensorplay.utils.data.RandomSampler.html

# RandomSampler

class tensorplay.utils.data.RandomSampler(data_source: [Sized](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sized), replacement: [bool](https://docs.python.org/3/library/functions.html#bool) = False, num_samples: [int](https://docs.python.org/3/library/functions.html#int) | [None](https://docs.python.org/3/library/constants.html#None) = None, generator: [Generator](tensorplay.Generator.html#tensorplay.Generator) | [None](https://docs.python.org/3/library/constants.html#None) = None)[[source]](../_modules/tensorplay/utils/data.html#RandomSampler)

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/library/functions.html#bool)) – samples are drawn on-demand with replacement if True , default=``False``.

- num_samples ([int](https://docs.python.org/3/library/functions.html#int)) – number of samples to draw, default=`len(dataset)`.

- generator ([Generator](tensorplay.Generator.html#tensorplay.Generator)) – Generator used in sampling.
