# WeightedRandomSampler Source: https://www.tensorplay.cn/docs/generated/tensorplay.utils.data.WeightedRandomSampler.html ```python class tensorplay.utils.data.WeightedRandomSampler(weights: Sequence[float], num_samples: int, replacement: bool = True, generator: Generator | None = None) ``` Samples elements from [0,..,len(weights)-1] with given probabilities (weights). Parameters: - weights (sequence) – a sequence of weights, not necessary summing up to one - num_samples ([int](https://docs.python.org/3/builtins/functions.html#int)) – number of samples to draw - replacement ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – if True, samples are drawn with replacement. If not, they are drawn without replacement, which means that when a sample index is drawn for a row, it cannot be drawn again for that row. - generator ([Generator](/docs/generated/tensorplay.Generator.html#tensorplay.Generator)) – Generator used in sampling.