dask.bag.Bag.random_sample

Bag.random_sample(prob, random_state=None)[source]

Return elements from bag with probability of prob.

Parameters
probfloat

A float between 0 and 1, representing the probability that each element will be returned.

random_stateint or random.Random, optional

If an integer, will be used to seed a new random.Random object. If provided, results in deterministic sampling.

Examples

>>> import dask.bag as db
>>> b = db.from_sequence(range(5))
>>> list(b.random_sample(0.5, 43))
[0, 3, 4]
>>> list(b.random_sample(0.5, 43))
[0, 3, 4]